Programming design patterns: facade or not?

Another guy from our team provided me with a library as banners for his web framework. Let me call this framework my friend’s frame.

It has a specific class that I need. Half of the properties exposed by this class are what I really need for my own application. The other half is not needed. To get the properties of this class, you need to do some string manipulation. Since I will develop my own structure on top of this class, I want to disable dependency as much as possible. Perhaps in the future another friend of mine will develop a better structure.

So what I did, I created a facade class for this class. My own structure accesses properties through my facade class. If the "My Friend Framework" has changed, I just need to change one facade class, and the rest will remain the same. In addition, string manipulation is performed inside the facade class. In addition, the facade class provides only the necessary properties. Thus, my own structure simply refers to properties as normal getter / setter.

However, I had an argument with this guy. He forces me to use his class directly, since he will never change the implementation of his class. Therefore, he tells me that writing a facade class really does not matter. But I do not agree.

Am I really wrong? I really believe that I'm right.

+4
source share
3 answers

In principle, you are wrong.

You are mistaken in the fact that what you are doing is not a facade. A façade is more often used when you have an API with many services. You can use all of these services together, but it can get complicated. The template is to stand on one API, a facade that coordinates the service’s appeal to useful, logical actions.

What you do is more like an adapter template. You adapt your class to your use case by placing another class in front of it.

Notice, I'm just pointing out a semantic problem, in practice, what you do is good design practice.

Also note that if you really do not intend to intend to update in the future, you may not need to solve this problem. Maybe YAGNI - you won’t need it.

+10
source

Sounds like a good design to me.

Facades usually provide an interface for a larger subsystem of classes, but I don’t understand why you also cannot use a facade to access one complex class.

It seems that the other person can be stubborn - so I think it's nice to separate his frame.

If your façade is easier to use, perhaps you can get it to add it to your infrastructure to provide it to everyone else.

+1
source

Your approach sounds good to me.

Just make sure you create an interface that is very independent of the actual implementation of the WHOLE infrastructure. Some others have indicated that this is an adapter, just because you are trying to separate one class, but I suspect the class is connected to others.

Try to answer the question: what secrets do you need to hide from this facade? Try posting some of the methods you want to review so we can discuss.

+1
source

All Articles