INTEGRATIVE CODING
DESIGN PATTERNS
A lower level of framework for structuring an application than architecture
(Sometimes, called micro-architecture).
Reusable collaborations that solve sub problems within an application.
Isn’t a finished design than can be transformed directly into code.
A description/template for how to solve problems that can use in many
situations.
Why Design Patterns?
Design patterns support object-oriented reuse at high level of abstraction.
Design patterns provide a “framework” that guides and constrains object-
oriented implementations.
Uses of Design Patterns
Speed up the development process by providing tested, proven development
paradigms.
Reusing design patterns helps to prevent subtle issues that can cause major
problem and improves readability.
Design Pattern description template
Selection Description
Pattern Name and Classification The name of the pattern and it's
classification (Creational, Structural,
Behavioral).
Intent A short statement about what the
pattern does.
Also known as Alternate well-known names for the
pattern.
Motivation An illustrative design problem that
shows how the pattern can solve the
problem.
Applicability Situations where the patterns can be
used.
Structure A graphical (UML) representation
showing the classes in the pattern.
Participants The classes that participate in the
pattern and their responsibilities.
Collaborations How the participants collaborate.
Consequences Benefits and trade-offs of using the
pattern.
Implementation Hints, pitfalls and techniques that can
be used to help implement the pattern.
Sample Code Code illustrations of using the pattern.
Known Uses Example of the pattern use in real
systems.
Related Patterns Other patterns closely related to the
current one.
Organizing Design Patterns
The Gang of Four (GoF) Design Patterns Book describes twenty-three
patterns arranged into three groups.
The groups help classify how the patterns are used.
The Three Types of Patterns are:
Creational Patterns used to help make a system independent of how its
objects are created, composed and represented.
Structural Patterns are concerned with how classes and objects organized
and composed to build larger structures.
Behavioral Patterns are used to deal with the assignment of responsibilities
to objects and communication between objects.
Example for Design Patterns
Creational Patterns
Abstract Factory- create instances of other objects
E.g. Creating GUI components for different GUI toolkits.
Factory Method- common interface for creating subclasses.
Singleton- creates only one instance of a class.
Structural Patterns
Decorator- adds more responsibilities to an object dynamically.
E.g. adding, scrolling to a text view
Façade- higher level unified interface to a set of objects in a subsystem.
Proxy- interface layer between objects.
Behavioral Patterns
Iterator- a means to access all the elements of objects sequentially.
Momento- captures and save the current state of an object.
Observer- when any numbers of objects (the Observers) need to be notified
automatically.
INTERFACES
Application program interface (API)
It is a toolset that programmers can use to help them create software.
How software components should interact.
Are set of requirements that govern how one application can talk to another.
Applications to share data and take actions on one another’s behalf without
requiring developers to share all of their software’s code.
Define exactly how a program will interact with the rest of the software
world---saving time, resources.
E.g. System-level-APIs- cut and paste LibreOffice document into an Excel
Spreadsheet.
E.g. Facebook APIs – Facebook users sign into many apps and Websites
using their Facebook ID.
E.g. Web APIs – games let players chat, post high scores and invite friends
to play via Facebook, right there in the middle of the game.
INHERITANCE
Derive a new class based on an existing class, with modifications or
extensions.
A subclass inherits all the variables and methods from its super classes,
including its immediate parent as well as all the ancestors.
Avoid duplication and reduce redundancy.
Types of Inheritance:
Single Inheritance
A derived class is created from a single base class.
In the given example, Class A is the parent class and Class B is the child
class since Class B inherits the features and behavior of the parent class
A.
Multi-level Inheritance
A derived class is created from another derived class.
In the given example, class c inherits the properties and behavior of class
B and class B inherits the properties and behavior of class B. So, here A
is the parent class of B and class B is the parent class of C. So, here class
C implicitly inherits the properties and behavior of class A along with
Class B i.e there is a multilevel of inheritance.
Multiple Inheritance
A derived class is created from more than one base class. This inheritance is
not supported by .NET Languages like C#, F# etc. and Java Language.
In the given example, class c inherits the properties and behavior of class B
and class A at same level. So, here A and Class B both are the parent classes
for Class C.
Multipath Inheritance
A derived class is created from another derived classes and the same base
class of another derived classes. This inheritance is not supported by .NET
Languages like C#, F# etc.
In the given example, class D inherits the properties and behavior of class C
and class B as well as Class A. Both class C and class B inherits the Class A.
So, Class A is the parent for Class B and Class C as well as Class D. So it's
making it Multipath inheritance.
Hierarchical Inheritance
More than one derived classes are created from a single base class and
further child classes act as parent classes for more than one child classes.
In the given example, class A has two children class B and class D. Further,
class B and class C both are having two children - class D and E; class F and
G respectively.
Hybrid Inheritance
This is combination of more than one inheritance. Hence, it may be a
combination of Multilevel and Multiple inheritances or Hierarchical and
Multilevel inheritance or Hierarchical and Multipath inheritance or
Hierarchical, Multilevel and Multiple inheritances.
Since .NET Languages like C#, F# etc. does not support multiple and
multipath inheritance. Hence hybrid inheritance with a combination of
multiple or multipath inheritances is not supported by .NET Languages.
Advantages of Inheritance
1. Reduce code redundancy.
2. Provides code reusability.
3. Reduces source code size and improves code readability.
4. The code is easy to manage and divided into parent and child classes.
5. Supports code extensibility by overriding the base class functionality within
child classes.
Disadvantages of Inheritance
1. In Inheritance base class and child class, both are tightly coupled. Hence If you
change the code of parent class, it will affect all the child classes.
2. In a class hierarchy, many data members remain unused and the memory
allocated to them is not utilized. Hence it affects the performance of your
program if you have not implemented inheritance correctly.