Question

I have some extra functionality i need to add which includes adding a new property to an object and extending methods in another class that handles this object. I'm dealing with source code of a product (in C# 2.0) we use which i really don't want to modify, i just want to extend on it.

I'd ideally like to have a separate assembly to do this so that it's clear it's our code. It seems like partial classes and delegates may be the way to go, but I'm not sure if this is possible to do. Has anyone done something similar? or know any good articles?

Was it helpful?

Solution

Check out the Decorator pattern. This is exactly what you are looking for. You can inherit the exiting classes and extend it with any additional logic you have. There's also a Proxy pattern if you want hiding some base functionality.

OTHER TIPS

Like hfcs101 said.

See if you can extend the class given some existing OO design patterns.

Take a look at:

See if you can find a pattern that closely matches your problem. Decorator looks like the best candidate.

Well you'll have to modify the original classes to also be "partial" classes and you'd have to make sure the namespace in the second assembly matches the one in the first and that both assemblies are references in the project that uses the assemblies. From there you are free to extend to your will.

Can you inherit from the class or is it sealed? Inheritance is the OO way to extend an existing class...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top