Professional Documents
Culture Documents
Contributors
What is OOP?
What is OOP?
What is OOP?
What is OOP?
What is OOP?
What is OOP?
Benefits of OOP
Benefits of OOP
Benefits of OOP
Benefits of OOP
Benefits of OOP
Benefits of OOP
Benefits of OOP
Abstraction
Abstraction
Abstraction
Example of Abstraction
Example of Abstraction
Example of Abstraction
Example of Abstraction
Manageability
Manageability
Manageability
Example of Manageability
Example of Manageability
Example of Manageability
Reusability
Reusabilty means using the same code again and again without
writing it twice.
Reusability
Reusabilty means using the same code again and again without
writing it twice.
It is a concept of OOP that is achieved via Inheritance.
Reusability
Reusabilty means using the same code again and again without
writing it twice.
It is a concept of OOP that is achieved via Inheritance.
Reuse enables faster development,less cost and high quality of
the software.
Example of Reusability
Example of Reusability
Readability
Readability
Productivity
Productivity
Maintainability
Maintainability
Maintainability
Example of Maintainability
Example of Maintainability
Why OOP?
Why OOP?
Encapsulation
Why OOP?
Encapsulation
Inheritance
Why OOP?
Encapsulation
Inheritance
Polymorphism
Encapsulation
Encapsulation
Encapsulation
Inheritance
Inheritance
Inheritance
Polymorphism
Polymorphism
Polymorphism
Why Guidelines?
Why Guidelines?
Why Guidelines?
Why Guidelines?
Why Guidelines?
Inheritance vs Composition
Inheritance vs Composition
Inheritance: is a relationship
Inheritance vs Composition
Inheritance: is a relationship
Composition: has a relationship
Inheritance vs Composition
Inheritance: is a relationship
Composition: has a relationship
Which one to use?
Inheritance vs Composition
Inheritance: is a relationship
Composition: has a relationship
Which one to use?
Design Guideline: Favour Composition over Inheritance
Inheritance
Composition
Interface
Interface
Can have abstract, default and static methods
Interface
Can have abstract, default and static methods
Cannot have non-abstract non-static methods
Interface
Can have abstract, default and static methods
Cannot have non-abstract non-static methods
Can have only static and final variables
Interface
Can have abstract, default and static methods
Cannot have non-abstract non-static methods
Can have only static and final variables
Cannot be instantiated
Abstract Class
Abstract Class
Can have both abstract and non-abstract methods
Abstract Class
Can have both abstract and non-abstract methods
Can have final, non-final, static and non-static variables
Abstract Class
Can have both abstract and non-abstract methods
Can have final, non-final, static and non-static variables
Cannot be instantiated
Example
Example
Example
Example
Example
Example
Solution
Some design principles that help coders achieve these are described in the
following slides.
DRY
DRY
DRY
Rule of 3
Rule of 3
Rule of 3
Rule of 3
Rule of 3
Evil switch
Evil Switch
The Evil Switch is a case, where DRY design principle comes in handy.
Evil Switch
Evil Switch
Evil Switch
In both cases, we can see that the switch condition statements are same.
Evil Switch
Now what if there were 20 functions with the same switch conditions?
And what if there were a 100 switch conditions?
Evil Switch
Copy-pasting does seem like an easy solution at first glance, but how
can you guarantee that you have correctly copy-pasted all the switch
cases?
Evil Switch
Copy-pasting does seem like an easy solution at first glance, but how
can you guarantee that you have correctly copy-pasted all the switch
cases?
And imagine, you need to add a new switch case, how can you
guarantee you will not miss any of the 20 places you need to add the
new case in?
Evil Switch
Evil Switch
Evil switches can easily be resolved to uphold DRY design principle using
strategy design pattern.
KISS
KISS
KISS
KISS
KISS
KISS
Example
Example
Example
Example
Example
Here comes the KISS awakening. Arrays are easier to understand than
Hashmaps.
Example
Example
Example
Example
YAGNI
YAGNI
YAGNI
Basically we have make sure that we are not doing anything that is not a
must.
Example 1
Example 1
Example 1
Example 1
Example 2
Example 2
Example 2
Example 2
Introduction to SOLID
What is SOLID?
What is SOLID?
What is SOLID?
History
History
History
SOLID is
SOLID is
Not a Library
SOLID is
Not a Library
Not a Framework
SOLID is
Not a Library
Not a Framework
Not a Pattern
SOLID is
Not a Library
Not a Framework
Not a Pattern
Not a Goal
Is Different
In any typical code there can be an entry point class A, which calls class
B, then B calls class C, C calls class D1. But when a change is required
that B should call class D2, then lots of code lines need to be changed
manually.
Is Different(continued)
Is Different(continued)
It is difficult to understand seeing the code that which class will be called
from C. It actually calls and Interface. Thus SOLID code is difficult from
any typical code.
Rigidity
Rigidity
Fragility
Rigidity
Fragility
Immobility
Rigidity
Fragility
Immobility
Viscosity
Rigidity
Fragility
Immobility
Viscosity
Needless Complexity
SRP
SRP
SRP
SRP
OCP
Open/Closed Principle:
OCP
Open/Closed Principle:
A class should be open for extension but closed for modification.
OCP
Open/Closed Principle:
A class should be open for extension but closed for modification.
One should be able to add new functionality to a class without
changing its existing code.
OCP
Open/Closed Principle:
A class should be open for extension but closed for modification.
One should be able to add new functionality to a class without
changing its existing code.
This reduces the risk of introducing new bugs and makes the code
more reusable.
LSP
LSP
LSP
LSP
ISP
ISP
ISP
ISP
DIP
DIP
DIP
DIP
DIP
THE END