samedi 28 mai 2022

How to apply Interface segregation principle?

I have a public interface that creates a bunch of different specific objects by client, and the only thing in common is that they all need to be serialized as xmls.

Something like this:

public interface IBuildXmlService
{
    XmlObject1 BuildClient1Xml(CustomObjectWithClient1Data data);
    XmlObject2 BuildClient2Xml(CustomObjectWithClient2Data data);
    XmlObject3 BuildClient3Xml(string string1, int int1);
    XmlObject4 BuildClient4Xml(CustomObjectWithClient4Data data);
}

Now this interface started to get big, and I'm definitely sure this is not a good sign. Also every time I inject the interface into a client specific class, that client specific class has access to all the other object creation methods for other clients.

Now the first thing I thought about was to just move the object creation method as a private method in client specific class, but this results in quite some big files.

Then I thought to use the factory method pattern to create a IXmlFactory with a BuildXml method for the object creation part, but this doesn't seem to work since I have different objects to return.

Can anyone give me some advice about what design pattern should I look for?

Aucun commentaire:

Enregistrer un commentaire