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 ...

Get Joy of Patterns: Using Patterns for Enterprise Development, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.