COM 244 Object Oriented Programming Some parts of
COM 244 Object Oriented Programming Some parts of those slides are adapted by the web page https: //www. tutorialspoint. com/design_pattern/
Design Patterns Introduction • They are critical part of OO design and programming concepts • They provide sophisticated and sustainable solutions to commonly encountered programming problems • Understanding them has become a serious part of any OO programmer’s approach 2
Design Patterns What are Design Patterns? Design patterns are solutions to general problems that software developers are encountered during software development. These solutions were obtained by several software developers over quite a considerable period of time. Essentially, design patterns deal with solving common design problems at a higher level and provides a description of a design solution that can applied to specific problems 3
Design Patterns What are Design Patterns? Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled, in 1994, Design Patterns - Elements of Reusable Object-Oriented Software which introduced the concept of Design Pattern in Software progress. • This book describes 23 patterns arranged into 3 groups. • Groups help classify how patterns are used: creational, structural, behavioral patterns 4
Design Patterns Design patterns are mainly divided into three parts. -Creational design patterns These design patterns are all about class instantiation. For instance: Factory Method, Abstract Factory , Builder etc. -Structural design patterns These design patterns are all about Class and Object composition. For instance: Adapter, Bridge, Facade etc. 5
Design Patterns -Behavioral design patterns These design patterns are all about Class's objects communication. For instance: Iterator, Mediator Observer, etc. 6
Singleton Pattern (Creational pattern) • This pattern comprises a single class which is responsible to create an object while making sure that only single object is generated. This class provides a way to access its only object. 7
Singleton Pattern 8
Singleton Pattern 9
Factory Pattern • This pattern is a creational pattern employing factory methods to handle the problem of creating objects without having to identify the exact class of the object that will be created. 10
Factory Pattern 11
Factory Pattern 12
Factory Pattern 13
Abstract Factory Pattern • Abstract Factory patterns work around a super-factory which generates other factories which is also called as factory of factories. Provide an interface for creating families of related or dependent objects without specifying their concrete classes. 14
Structural Pattern • Adapter Pattern This pattern provides a bridge between two unsuited interfaces. This pattern includes a single class which is responsible to join functionalities of incompatible interfaces 15
Adapter Pattern The Target interface describes the domain specific interface that the Client used. This allows the client to cooperate with objects that employs the interface. Besides, the Adaptee is the current interface that desires adapting in order for our client to interact with it. The Adapter adapts the Adaptee to the Target interface. Overall, it interprets the request from the client to the adaptee 16
Facade Pattern • Facade pattern hides the complexities of the system and provides an interface for the client. This interface allows the client to easily access a system. 17
Behavioral Pattern Structure • Iterator Pattern This pattern allows to access the elements of a collection object in sequential manner without any need to know its underlying representation in especially JAVA and. Net platforms. 18
Iterator Pattern 19
Mediator Design Pattern • This pattern is employed to reduce communication complexity between numerous objects or classes. The mediator class deals all the communication issues between different classes and supports easy maintenance of the implementation. An example of tower at a controlled airport shows this pattern quite well. The pilots of the different aircrafts approaching or departing the terminal area communicate via the tower instead of explicitly communicating with each other. 20
Mediator Design Pattern 21
MVC Design Pattern The Model View Controller (MVC) design pattern specifies that an application involves a data model (model), presentation information (view), and control part (control). The pattern entails that each of these be separated into different objects. 22
MVC Design Pattern 23
MVC Design Pattern • A simple example using MVC pattern The code is adapted from: 24
MVC Design Pattern 25
MVC Design Pattern (Output) 26
- Slides: 26