1.

When To Use Composite Design Pattern In Java? Have You Used Previously In Your Project?

Answer»
  • This design pattern question is asked on Java interview not just to check FAMILIARITY with Composite pattern but also, whether candidate has real life experience or not.
  • Composite pattern is also a core Java design pattern, which allows you to treat both whole and part OBJECT to treat in SIMILAR way.
  • Client code, which deals with Composite or individual object doesn't differentiate on them, it is POSSIBLE because Composite class also implement same interface as there individual part.
  • One of the good example of Composite pattern from JDK is JPanel class, which is both Component and Container.
  • When paint() method is called on JPanel, it internally called paint() method of individual components and LET them draw themselves.
  • On second part of this design pattern interview question, be truthful, if you have used then say yes, otherwise say that you are familiar with concept and used it by your own.
  • By the way always remember, giving an example from your project creates better impression.



Discussion

No Comment Found