How to implement common code across classes?

In my C# project, I have few classes – A,B,C,D,E. There are some common methods that are used across these classes, but not all at the same time. For instance, common method in class C1 is used in A, B, C2 is used in A, C, C3 is used in B,D,E. The classes A,B,C,D,E all inherit from a common base class which has few methods that would be used in C1, C2, C3 common methods. How do I achieve this?

a) Put a proper inheritance in place for A,B,C,D,E like this – BaseClass -> (All common method in one class) -> A,B,C,D,E

b) Pass the instance to C1, C2, C3 classes in new() method using this keyword. (this is the present approach)

Please help me as to which one I should choose and why? And if there are any other elegant ways of implementing this? Note that I cannot pass only required properties to C1, C2, C3. The common methods present in C1, C2, C3 need access to the methods present in the Base Class and they are not static.

submitted by /u/argumentnull
[link] [comments]

Leave a Reply