"Absztrakt Gyártó terv minta" "Ebben a példában autókat szeretnénk legyártatni, konkértan Porsche-t, Toyota-t és Ford-ot. A tervmintának megfelelően van egy absztrakt osztályunk mely a gyárak felülelét definiálja, illetve van egy, ami pedig az alkatrészekét. Mellesleg egy autó két részből áll a vázból és a motorból." CarPartFactory>>makeCar self subclassResponsibility CarPartFactory>>makeEngine self subclassResponsibility CarPartFactory>>makeBody self subclassResponsibility FordFactory>>makeCar ^FordCar new FordFactory>>makeEngine ^FordEngine new FordFactory>>makeBody ^FordBody new ToyotaFactory>>makeCar ^ToyotaCar new ToyotaFactory>>makeEngine ^ToyotaEngine new ToyotaFactory>>makeBody ^ToyotaBody new Object subclass: #CarAssembler instanceVariableNames: 'factory' classVariableNames: '' poolDictionaries: '' CarAssembler>>factory: aCarPartFactory "Setter method" factory := aCarPartFactory CarAssembler class>>using: aCarPartFactory "Instance creation method" ^self new factory: aCarPartFactory CarAssembler>>assembleCar | car | "Create the top-level part, the car object which starts out having no subcomponents, and add an engine, body, etc." car := factory makeCar. car addEngine: factory makeEngine; addBody: factory makeBody. ^car CarPartFactory>>makeCar ^self carClass new CarPartFactory>>makeEngine ^self engineClass new CarPartFactory>>makeBody ^self bodyClass new FordFactory>>carClass ^FordCar FordFactory>>engineClass ^FordEngine FordFactory>>bodyClass ^FordBody PorscheFactory>>carClass ^PorscheCar PorscheFactory>>engineClass ^PorscheEngine PorscheFactory>>bodyClass ^PorscheBody Object subclass: #CarPartFactory instanceVariableNames: 'partCatalog' classVariableNames: '' poolDictionaries: '' CarPartFactory class>>new ^self basicNew initialize CarPartFactory>>initialize partCatalog := Dictionary new FordFactory>>initialize super initialize. partCatalog at: #car put: FordCar; at: #body put: FordBody; at: #engine put: FordEngine. ^self PorscheFactory>>initialize super initialize. partCatalog at: #car put: PorscheCar; at: #body put: PorscheBody; at: #engine put: PorscheEngine. ^self CarPartFactory>>make: partType "Create a new part based on partType." | partClass | partClass := partCatalog at: partName ifAbsent: [^nil]. ^partClass new “anAutoFactory make: #engine. anAutoFactory make: #body.” “anAutoFactory makeEngine. anAutoFactory makeBody.” Object subclass: #CarPartFactory instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' CarPartFactory class instanceVariableNames: 'partCatalog' CarPartFactory class>>make: partType "We moved this method; it's a class method now." | partClass | partClass := partCatalog at: partType ifAbsent: [^nil]. ^partClass new CarPartFactory class>>new partCatalog isNil ifTrue: [self initialize]. ^self basicNew CarPartFactory class>>initialize "Initialize the part catalog. This is now a class method." partCatalog := Dictionary new FordFactory class>>initialize "Initialize the *local* part catalog." super initialize. partCatalog at: #car put: FordCar; at: #body put: FordBody; at: #engine put: FordEngine. CarPartFactory>>make: partType "Create a new part based on partType." ^self class make: partType CarPartFactory class>>fordFactory "Create and return a new Ford factory." | catalog | catalog := Dictionary new. catalog at: #car put: FordCar; at: #engine put: FordEngine. ^self new partCatalog: catalog CarPartFactory class>>porscheFactory "Create and return a new Porsche factory." | catalog | catalog := Dictionary new. catalog at: #car put: PorscheCar; at: #engine put: PorscheEngine. ^self new partCatalog: catalog “carFactory := CarPartFactory fordFactory. carFactory make: #engine.” CarPartFactory>>makeCar: manufacturersName "manufacturersName is a Symbol, such as #Ford, #Toyota, or #Porsche." | carClass | carClass := Smalltalk at: (manufacturersName, #Car) asSymbol ifAbsent: [^nil]. ^carClass new CarPartFactory>>makeEngine: manufacturersName | engineClass | engineClass := Smalltalk at: (manufacturersName, #Engine) asSymbol ifAbsent: [^nil]. ^engineClass new “carFactory := CarPartFactory new. car := carFactory makeCar: carCompany. car addEngine: (carFactory makeEngine: carCompany);”