0

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.

disruptive
  • 5,687
  • 15
  • 71
  • 135
  • Couldn't you just declare class C as public class `C:DPM` ? Then you could either inherit and implement only the exceptions in A and B (with virtual inits), or check for type T directly inside C ( `if(typeof(T)==typeof(Temp ) ...` ) – Me.Name Apr 28 '14 at 11:08
  • We have a massive code set so we template our classes with many types, this looks horrific! You say you cant refactor, but can you facade and simplify this for your client code? – brumScouse Apr 28 '14 at 11:12
  • @brumScouse Facade? What do you mean by this? – disruptive Apr 28 '14 at 15:27

1 Answers1

0

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?

B2K
  • 2,541
  • 1
  • 22
  • 34
  • ...What the client wants. I can not change anything but the new structures, so I have no remit at all other than to try to integrate these. :( – disruptive Apr 28 '14 at 15:23