dimanche 1 juillet 2018

Composition vs facade pattern

I found a response that made me understand a bit more class compositioning.

class Engine
{

}

class Automobile
{

}


class Car extends Automobile // car "is a" automobile //inheritance here
{ 
 Engine engine; // car "has a" engine //composition here

}

but isn't this a facade pattern? Isn't facade about making the class simpler by dividing into subclasses? What's then the difference between composition and facade?

Or maybe I get it wrong. The facade is a design pattern but the composition is more like a good practice to follow. Can we say that using facade is doing composition?

Aucun commentaire:

Enregistrer un commentaire