O'Reilly logo

Joy of Patterns: Using Patterns for Enterprise Development, The by Brandon Goldfedder

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CompositePart.java

 package ProductConfig; import java.io.PrintStream; import java.util.*; public class CompositePart extends BasicPart { // use a fixed algorithm for price CompositePart(String name, String description, double price) { super(name, description, price); m_useFixed = true; m_parts = new Vector(); } // Use a calculated algorigthm for price CompositePart(String name, String description) { super(name, description, 0); m_useFixed = false; m_parts = new Vector(); } private double sumChildrenPrices() { double price = 0; for (Enumeration e = m_parts.elements() ; e.hasMoreElements() ; ) { Part tmpPart = (Part)e.nextElement(); price = price + tmpPart.getPrice(); } return price; } public void addPart(Part part) throws NotACompositeException ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required