This presentation provides an overview of design patterns for object-oriented programming languages. It covers Observer, Factory, Abstract factory, Composite, and Facade patterns.
• Encapsulation - Separation of concerns and information hiding • Modularization - Cohesive and loosely-coupled abstractions • Hierarchy - Hierarchical organization of abstractions
Practice Course and a few stakeholders (Students and Instructors) • Any change in the course must be notified to all the stakeholders • Now, think about its implementation
observer (a new Student or a new Instructor)? • You need to make multiple changes • What about adding a new category of observers; for example "Organizer"!
new observers. • Is it easier? • In the first implementation, `Course` class is "tightly-coupled" to `Student` and `Instructor` classes. While in the second case, `Course` class is "loosely-coupled" to it's observers. • Congratulations!! You have just learned the first design pattern :)
of communicating objects and classes that are customized to solve a general design problem in a particular context. (By Gang of Four) • Design patterns are solutions to commonly occurring design problems.
create and when to create • Examples: Factory, Abstract Factory, Builder • Structural - patterns answer how to compose/structure • Examples: Adapter, Composite, Decorator • Behavioral - patterns describe how a group of objects cooperate to carry out a task • Examples: Observer, Strategy, Visitor
there is a course, students, instructors, and organizers. • The course has a start time and end time. • If any of the timing changes, the stakeholders have to be notified. Implement a program that notifies the stakeholders whenever the time changes for the course.
for Java code: • LOC (Lines of Code) • Number of classes • Number of methods. • Write the metrics in a file. • Use regular expressions to calculate the aforementioned metrics. • Use the read & write methods from the Utility class created in Exercise 2.
objects and classes that are customized to solve a general design problem in a particular context. (By Gang of Four) • Design patterns are solutions to commonly occurring design problems.
create and when to create • Examples: Factory, Abstract Factory, Builder • Structural - patterns answer how to compose/structure • Examples: Adapter, Composite, Decorator • Behavioral - patterns describe how a group of objects cooperate to carry out a task • Examples: Observer, Strategy, Visitor
us assume you have families of objects to instantiate • Widget library providing UI elements such as Button and TextBox • The library instantiate UI elements based on the platform such as Windows and Linux
can be easily exchanged) • Separation of concerns (Object lifetime management is separated from object use) • Liabilities • GoF Abstract Factory only covers object creation, not object disposal
algorithm required in many situations: • Clients do not want to be dependent on a supplied default algorithm • Suitability of an algorithm may change based on the context (input, platform, ...) • Integrating new algorithms should be easy (without modifying existing code, if possible) • Examples • Compression algorithm, sort algorithm
Easier extensibility • Applicability • Many related classes differ only in their behavior • You need different variants of an algorithm • A class defines many behaviors, and these appear as multiple conditional statements in its operations
with following requirements • Preserve hierarchical structure • Same interface for both compound or atomic objects for clients • It should be easy to extend the hierarchy with new element types
a complex system • De-couples the subsystem for clients and other subsystems, thereby promoting subsystem independence and portability • Layers the subsystem • Use façade to define an entry point to each subsystem level • If subsystems are dependent, then the dependencies between them can be simplified by making them communicate with each other solely through their facades
another way to implement the same functionality but by using string comparison. Pay attention to your design (hint: implement strategy and factory patterns) 5. Extend the above program and implement a segregated interface to compute all the supported metrics. Write all the computed metrics to a CSV file. (hint: use Facade pattern) Deadline: 25 May, 2017