disruptive
disruptive

Reputation: 5946

Merging two class structures which each rely on complex inheritance c#

We have a massive code set, so each of the classes is of the form:

public class A :
        DPM<Time, Data, TypeAKindA,
            TypeAKindB, TypeAKindC,
            TypeAKindC, TypeAkindD, TypeAKindE>

public class B:
        DPM<Temp, Data, TypeBKindA,
            TypeBKindB, TypeBKindB,
            TypeBKindC, TypeBKindD, TypeBKindE>

So Time is specific struct for example which differs from Temp.

The problem, is for each of these classes I have an init, constructor, so for example in the init, I am doing this specific to the class name. I.e. A goes off and does something specific for each class.

This is a massive code-set so I cannot re-factor. I'd like to combine these, so I have one class call it C, that will basically either execute the functionality of each or somehow merge them. I cannot change class DPM, and this is a complex structure with plenty of where clauses in it.

It looks like this:

public abstract class DPM<TypeA, TypeB, TypeC, , ... > : ID

where ID is an interface.

An example of the issue is the class DPM inherited has a property called _xyz which is populated with different values in .init() depending on whether it is called from Class A or Class B. And I don't know the dependencies downstream - so where is called or used later in the code.

Any suggestions very welcome.

Upvotes: 0

Views: 259

Answers (1)

B2K
B2K

Reputation: 2611

So you cannot refactor, but you are trying to refactor it. You will need to rename any common properties of differing types. Of course, this begs the question of whether you should do so.

I would suggest that chaining additional types onto the class definition would only make matters worse. That being the case, you could possibly refactor to common interfaces. Have you considered posting a more detailed question on StackExchange's CodeReview site?

Upvotes: 0

Related Questions