Can you explain Composite Pattern?

 Posted by ArticlesMaint on 9/25/2009 | Category: Design Pattern & Practices Interview questions | Views: 4402

Composite pattern allows treating different objects in a similar fashion. Figure ‘Uniformity’ shows how different objects are called in a uniform manner.

Figure: - Uniformity

In order to treat objects in a uniformed manner we need to inherit them from a common interface. Figure ‘Common Interface’ shows the objects inheriting from a common interface.

Figure: - Common Interface

Figure ‘Client code for composition’ shows how we added all the different kind of objects in to one collection and then called them in a uniform fashion.

Figure: - Client code for composition

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Mongaman on: 7/30/2010
The clsLine class definition contains write statement "Draw Circle" whereas it should be "Draw Line".

Login to post response