I have a report class that stores information.
A report "is a Document", so I want the report class
extend document. But how do i store subclasses in the the Document class.
I cant super all the info from the report class creates from the constructor.

Member Avatar for ztini

If I understand right, a report is a document, but a document may have multiple reports (and other classes). This is a classic example of the composite design pattern. http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-designpatterns.html

An easy way to understand the composite pattern is with recipes. Take for instance a burrito. This is a recipe that is made up of ingredients (salsa, beef, cheese). Ingredients can either be single ingredient or another recipe (salsa is tomatoes, onions, peppers).

Hope that analogy helps; this is one of the harder design patterns to get down. Also, you will probably want to look at using the visitor pattern in conjunction with the composite (they almost always go hand-in-hand).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.