Wednesday 15 September 2010

language agnostic - Can the Composite (from the Composite Pattern) have an isLeaf() method? -


Is there a reason composite should not contain isLeaf () Method?

(Since the point of this method (if I'm not mistaken) to be able to use address and composite the same thing In the form, without the difference?)

Or is it absolutely right if I can still use both of them as if they are the same thing, but also know Is that what if I want to?

One of the debate questions about the mixed class if you are using an interface , You can get it into the shared interface, and then in the leaf class, an unsupported operation can throw exceptions.

You can also use visitors to handle different nodes types, so the classic filesystem where the folder / file composite is the root of it, you can make a visitor to a different variety (Or handle only specific types)

Do you have the plan that you will use it? There may be a better way to understand the value of the specific case method.

No comments:

Post a Comment