OOP Concepts & Design Patterns
Contents
• OOP Concepts
• Design Patterns
• How to Select a Design Pattern
OOP Concepts
• Object Oriented is a popular design approach for analyzing
and designing an application
• Most of the languages like C++, Java use object oriented
design concept
• Object-oriented concepts are used in the design methods
such as classes, objects, polymorphism, encapsulation,
inheritance, dynamic binding, information hiding, interface,
constructor, destructor
• The main advantage of object oriented design is that improving the
software development and maintainability
• Another advantage is that faster and low cost development, and creates
a high quality software
• Well-suited for programs that are large, complex and actively updated or
maintained
• The disadvantage of the object-oriented design is that larger program
size and it is not suitable for all types of program
Different Terms Related to Object Design
Class
• A class is a collection of method and variables
• It is a blueprint that defines the data and behavior of a type
• Ex. Human being as a class
• A class is a blueprint for any functional entity which defines
its properties and its functions
• Like Human being, having body parts, performing various actions
Inheritance
• Inheritance is a feature of object-oriented programming that
allows code reusability when a class includes property of another
class
• Considering Human being, a class, which has properties like
hands, legs, eyes, mouth, etc., and functions like walk, talk, eat,
see, etc.
• Man and Woman are also classes, but most of the properties and
functions are included in Human being
• Hence, they can inherit everything from class Human being using
the concept of Inheritance
• Objects
• My name is Ben, and I am an instance/object of class Man
• Abstraction
• Abstraction means, showcasing only the required things to the
outside world while hiding the details
• Ex. Human being’s can talk, walk, hear, eat, but the details of the
muscles mechanism and their connections to the brain are hidden
from the outside world
• Encapsulation
• Hiding unnecessary details from the user
• For example, when we call from our mobile phone, we select the
number and press call button
• But the entire process of calling or what happens from the
moment we press or touch the call button to the moment we start
having a phone conversation is hidden from us
• Polymorphism is a feature of object-oriented programming
languages that allows a specific routine to use variables of
different types at different times
Ex. Polymorphism in Java
Design Classes
• A set of design classes provides the design details
• There are five different types of design classes as follows
and each type represents the layer of the design architecture
• User Interface Classes
• These classes are designed for Human Computer Interaction(HCI)
• Business Domain Classes
• Identifies the attributes required to implement the elements of
the business domain
• Process Classes
• Is needed to manage the business domain class
• Persistence Classes
• Represents the data stores that will persist beyond the execution
of the software
• System Classes
• Implement software management and control functions
Design Class Characteristics
• Complete and Sufficient
• A design class should be complete encapsulation of all attributes
and method that can be reasonably be expected to exist for class
• Primitiveness
• Method associated with design class should be focused on
accomplishing one service for class. The class should not provide
another way to accomplish the same thing
Design Class Characteristics
• High Cohesion
• A cohesive design class has a small and focused set of
responsibilities
• Low-coupling
• A class should be associated with the minimum number of other
classes to allow it to fulfill its responsibilities. If a design model is
highly coupled then the system is difficult to implement, to test
and to maintain over time
Design Patterns
Basic Concepts of Design Patterns
• In software engineering, a design pattern is a general repeatable
solution to a commonly occurring problem in software design
• It is a description or template for how to solve a problem that
can be used in many different situations
• Each design pattern systematically names, explains, and
evaluates an important and recurring design in object-oriented
systems
• The goal is to capture design experience in a form that people
can use effectively
• To this end, some of the most important design patterns are
documented and present them as a catalog
• In general, a pattern has four essential elements
• Pattern Name
• Problem
• Solution
• Consequences
• Pattern Name
• Used to describe a design problem, its solutions, and
consequences in a word or two
• Naming a pattern increases our design vocabulary and makes it
easier to think about designs and communicate to others
• Finding good names has been one of the hardest part
• Problem
• Describes when to apply the pattern
• It explains the problem and its context
• Solution
• The solution doesn't describe a particular concrete design or
implementation. Because a pattern is like a template that can be
applied in many different situations
• Describes the elements (classes and objects) that make up the
design, their relationships, responsibilities, and collaborations
• Consequences
• They are the results and trade-offs of applying the pattern. These
are the costs and benefits of applying the patterns
Design Pattern - Benefits
• Design patterns can speed up the development process by
providing tested, proven development paradigms
• Reusing design patterns helps to prevent subtle issues that
can cause major problems
• Improves code readability
• Design patterns provide general solutions, documented in a
format
• Makes it easier to reuse successful designs and architectures
Characteristics of Design Pattern
• Smart
• Elegant solutions that a novice would not think of immediately
• Generic
• Not normally depend on a specific system type, programming
languages or application domains. They are generic in nature
• Well Proven
• They have been identified from real object oriented systems, and
have been successfully tested in several systems
Characteristics of Design Pattern
• Simple
• They are usually quite small involving small number of classes. The
complex systems are built using different design patterns and their
combinations
• Reusable
• They are documented in such a manner to increase reusability
• Object Oriented
• They are built with the basic object oriented mechanisms such as
classes, objects, generalization and polymorphism
How to Select a Design Pattern?
• GOF (Erich Gamma, Richard Helm, Ralph Johnson and John
Vlissides) introduced the principles of design pattern
• With 23 design patterns in the catalog to choose from, it might
be hard to find the one that addresses a particular design
problem, especially if one is new and unfamiliar to the catalog
• Different approaches to finding the design pattern that's right for
the problem is as shown
• Consider how design patterns solve design problems
• Find appropriate objects, determine object granularity, specify
object interfaces, and several other ways in which design patterns
solve design problems
• Scan Intent Sections
• Read through each pattern's intent to find one or more that sound
relevant to your problem
• Study how Patterns Interrelate
• Studying the graphical representation of relationships between
design patterns can help direct you to the right pattern or group of
patterns
• Study Patterns of Like Purpose
• Study the similarities and differences between creational patterns,
structural patterns and behavioral patterns
• Examine a Cause of Redesign
• Look at the patterns that help you avoid the causes of
redesign
• Consider What Should be Variable in your Design
• Consider what you want to be able to change without redesign
• The focus here is on encapsulating the concept that varies
Organizing the Catalog
• There are many design patterns, we need a way to organize them
Design Pattern Space
• Design patterns are classified by two criteria as in the fig.
• Purpose
• Reflects what a pattern does
• Patterns can have either creational, structural, or behavioral
purpose
• Creational patterns concern the process of object creation
• Structural patterns deal with the composition of classes or objects
• Behavioral patterns characterize the ways in which classes or
objects interact and distribute responsibility
• Scope
• Specifies whether the pattern applies primarily to Classes or to Objects
• Class Patterns
• Deal with relationships between classes and their subclasses
• These relationships are established through inheritance, so they are static
(fixed at compile-time)
• Object Patterns
• Deal with object relationships, which can be changed at run-time and are
more dynamic
• Only patterns labeled "class patterns" are those that focus on class
relationships
• Note that most patterns are in the Object scope