Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object oriented design question

Tags:

c#

oop

I need to create a class which is building up an XML config file based on another objects.

There are 3 various objects. The building algorithm is very similar for all objects,but not same.

I was thinking of using a base class with an abstract method and then just create a derived classes with where I'd override the abstract method.

But the problem is those 3 object doesn't have a common interface or base class. Those objects are third party components. I can't refactor them. So there isn't any common contract for all objects.

Is there any convenient solution for this situation ? Maybe some design pattern I don't know about ?

like image 838
user137348 Avatar asked Jan 24 '11 10:01

user137348


2 Answers

You could define a XMLSerializable abstract class and then use the Adapter pattern to adapt these third party components into XMLSerializable objects

like image 186
PaoloVictor Avatar answered Oct 06 '22 01:10

PaoloVictor


you can create your 3 custom class extending them respectively [I am not sure about C#], and implement a common contract.

like image 25
jmj Avatar answered Oct 06 '22 02:10

jmj