Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27187

Design pattern "Facade"

I'm working on the issue of design patterns. In this case I want to implement design pattern 'Facade'

I know that 'Cocoa Touch' offers us complete solutions for applying design patterns in our projects (for example NSNotificationCenter - implements observer design pattern)

My questions is next: - do we have ability to using design pattern 'Facade' as well as in the case of the observer design pattern.

Now I implement 'Facade' like this:

For example i have some classes which implements some calculations. The 'Facade' class combine all classes which I needed to calculations.

For example i have classes A, B, C and Facade (which contain A, B and C classes).

When I want to calculate something I just create my 'Facade' and pass some argument for calculation. In this case I don't know about classes A, B, C and this Facade object provides me one access point only.

This design pattern encapsulates objects and simplifies the application.

Is it correct implementation?

Upvotes: 7

Views: 5218

Answers (4)

Developex
Developex

Reputation: 328

Another a good example for implementing facade pattern - pizza call service. For example, pizza service (subsystem) is very large and it consists of three departments (interfaces) : order department, discount department, delivery department. Each departments has own logic and interfaces. You can simply implement facade pattern on it. Here this example in more details.

Upvotes: 7

hburde
hburde

Reputation: 1441

A Facade is defined as unified interface to a bunch of interfaces - sort of higher level interface to reduce the complexity. Instead of dealing with several classes and knowing the API's of each its reduced to the facade. Your explanation looks OK to me.

Upvotes: 7

mishadoff
mishadoff

Reputation: 10789

It is correct explanation (i don't see implementation). Nice association to Facade pattern in real life is remote control - you can run TV functions, DVD and so on.

Upvotes: 4

isaac
isaac

Reputation: 4897

The motivation behind the facade pattern is to provide a simplified interface for often-used cases, while accommodating the ability to reach past the simplified interface and interact with more complex aspects of the classes behind the facade when neccessary. As you've described your implementation, it would certainly seem to fit the description, and there is no reason you couldn't use a facade pattern in combination with a notification/observer pattern...

Upvotes: 1

Related Questions