SOLID Object Oriented Principles
The Single Responsibility Principle
DEMO: The Problem
In
this class diagram, Rectangle class depends on GUI library package.
Same way Graphical Application and Geometry Service are using Rectangle
Class. If anything changes on GUI will affect the Rectangle class,
hence it should be compiled likewise Geometry services and Graphical
Application should be compiled.
The problem in Business Implementation
Problem Analysis
Refactoring Better Design
The Open / Closed Principle
DEMO: The Problem
The problem Analysis
Refactoring to a Better Design
Adding New rule easily
The Liskov Substitution Principle
Demo: The Problem
Refactoring to a Better Design
The Interface Segregation Principle
DEMO: The problem
Problem 1:
Note: In order to use Validate method inside of membership provider, we need to implement all other abstract base members which we do not use.
Problem 2:
Problem Analysis
Refactoring to a Better Design
Design Smells and Tips
The Dependency Inversion Principle
DEMO:The Problem
Refactoring to a Better Design
Design Smells
The Dependency Inversion Principle, Part 2
Traditional Programming
Refactoring Class Dependencies
First step is need to change the Static method to Instance method.
The Don't Repeat Yourself Principle, Part 1
Demo App and Analysis
Refactor Magic Strings
Refactoring Connection String
Refactoring Print Statements
Refactoring Magic Numbers
Refactoring Format Strings
Refactoring Duplicate Logic
Refactoring Repeated If-then Logic
Refactoring Conditional Polymorphism
The Don't Repeat Yourself Principle, Part 2
Test and Static Cling
Demo of Adding Integration Tests
Demo of Adding Unit Tests
Demo of MOCK Objects
Principles of Object Oriented Design - The Don't Repeat Yourself Principle, Part 3
Repeated Execution Pattern
Demo of Refactoring using Action of T
Demo of Refactor Data Access
Demo: Find Duplicate Code – Atomiq
Code Generation
Repetition in process
Demo of Automation with MS Build
Dependency Inversion
Dependency Inversion
Introduction
Bob’s Copy Program Example
Copy program without DIP
If we add more Writing functionality then this program will become more difficult and complicated because it lots more depending on lower modules.
Copy program with DIP
Layering
Button/Lamp Example
In
this button Lamp example, button is dependent on Lamp. If you want to
control the Lamp in some other way or Use that button in some other
purpose then it is very difficult. As this implementation is tightly
coupled.
This below implementation is Loosely coupled, we could add more devices in that button if we implement below design.
Inversion of Control
Interface Inversion
Interfaces without Inversion of Control
If
we use more Interfaces then it will create problem when we use that
interfaces in Client or user level. For example, if you want to make
match between IKangaroo and MikeTyson, you have to know about Method
inside of those interfaces. Here low level Kangaroo class define its
own interface.
Here the Client boxing Match is creating IBoxer interface, all the low lever classes should implement this.
Flow Inversion
Creation Inversion
Dependency Injection
Below
picture represent the Class with have all of its dependencies
together. Basically it does not implement dependency inversion.
Below picture represent the Class will get all of its dependencies from someone else like caterers.
Constructor Injection
Setting Injection
Interface Injection
Building an IoC Container
Visualizing Container
Demo of Manual Dependency Injection
Resolving Dependencies
Building the Real IOC Container
Using Unity
What is Unity?
Setting up Unity
Registering
Using the Container
Overriding Parameter
Controlling Life Cycle of Container Objects
Singleton Style
Using Castle Windsor
Setting up the Castle Windsor
Registering
Using the Castle Windsor
Controlling the Life Cycle of object
Singleton
Non Singleton
Using Structure Map
Setting up the Structure Map
Registering
Using the Container
Controlling Life Cycle
Not Singleton
Singleton
Using Ninject
What is Ninject
Setting up Ninject
Registering
Using the Container
Controlling Life Cycle
Non Singleton
Singleton
Object Oriented Programming with C#
Procedural code Approach
- It works top to bottom
- Here all the business logic are inside the main procedure
Encapsulation approach
- Here procedural code needs to be broken up into multiple pieces with abstraction
- In this approach gives experience driving car without knowing about how engine works.
Inheritance and Polymorphism
Inheritance is always problem in Software engineer when derived class inherits some base abstract classes. In inheritance, we do not know who is calling whom, who will call the implemented method in derived class and so on.....
Interface Implementation
Interface plays important role when we face the situation where to derive multiple base classes.
This is perfect solution for all the inheritance problem which we faced before.
Directional Dependencies
Dependencies Point Out
Dependencies Point In
No comments:
Post a Comment