jgs 00000001 Announcement § Midterm Exam Wednesday March 10 During the lecture time. No exceptions § Final Exam Wednesday April 21 During the lecture time. No exceptions
jgs 00000001 Decorator vs Inheritance § Both allow you to change how an object behaves § The decorator pattern can be used to make it possible to extend (decorate) the functionality of a certain object at runtime. § Inheritance adds behavior at compilation-time.
jgs 00000001 Main class MainApp { static void main() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); } }
jgs 00000001 HelperCompanion public class HelperCompanion extends CompanionDecorator { @Override public void doSomething(){ super.doSomething(); System.out.print(" I am here to help you. "); } }
jgs 00000001 AffectiveCompanion public class AffectiveCompanion extends CompanionDecorator { @Override public void doSomething(){ super.doSomething(); System.out.print(" I am here to cheer you."); } }
jgs CSE 460 Software Analysis and Design Javier Gonzalez-Sanchez [email protected] Fall 2020 Disclaimer. These slides can only be used as study material for the class CSE460 at ASU. They cannot be distributed or used for another purpose.