Académique Documents
Professionnel Documents
Culture Documents
COURS N°4
Principe ouvert/fermé
Le décorateur
La fabrique
PRINCIPE
OUVERT/FERMÉ
Use(s : Server)
Server
doSomething()
<<Interface>>
Client
IServer
Use(s : IServer)
doSomething()
Server1
Car
Car(MotorType m)
start()
<<Énumeration>>
MotorType
Motor
GAS
DIESEL
GPL
ELECTRIC
GasMotor DieselMotor
start() start()
• respecte O ?
Car
<<Énumeration>>
Car(m : MotorType) MotorType
GAS
DIESEL
GPL
ELECTRIC
Motor
MotorFactory
GasMotor
DieselMotor
<<Interface>>
CreateMotor
Car create() : Motor
+Car(typeMotor : string) *
Motor MotorFactory
createMotor(type:string) : Motor
register(cm : createMotor, type:string)
GasMotor
DieselMotor
constructors *
Factory
<<Interface>>
Mother
Constructor Types() : [*]
Mother() Create(type) : Mother
Create() : Mother
Child1() Child2()
<<instantiate>>
<<instantiate>>
return constructors[Type].create();
}
Human
+Human(name:string)
Animal
Dog <<property> Name :string
Animal(name : string)
Bird
+Dog(name:string)
+Speak() : string
+Speak() : string +Bird(name:string)
+Species() : string
+Species() : string +Speak() : string
+Food() : string
+Food() : string
+ToString() : string
+Race() : string
return constructors[type].Create(name);
}
animals.Items.Add(a);
}
operation()
Decorator
operation()
Decorator( c : IComponent)
Decorator1 Decorator2
operation() operation()
10;20
10;20;30
10;20;30 RED
M3105 Alexandre Guidet
Module M3105 – Programmation objet avancée
PROCHAIN COURS
Principe D
Adaptateur, Observateur