OOP And OOAD




 SOLID Object Oriented Principles


The Single Responsibility Principle


image



image



image



image



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.

image



The problem in Business Implementation

image



image



Problem Analysis
image



Refactoring Better Design

image


image


image


image


image


image





The Open / Closed Principle


image



image



image



image



DEMO:  The Problem

image


image



The problem Analysis

image



image



Refactoring to a Better Design

image



image



image


image


image


image


image


image


Adding New rule easily
image


image



image



image




The Liskov Substitution Principle


image


image



image



image



image



Demo: The Problem
image


image


image


image



image



image


image



Refactoring to a Better Design
image



image



image


image




The Interface Segregation Principle


image



image



image



DEMO:  The problem

Problem 1:

image


image

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:

image


image


image


image


image



Problem Analysis
image



image



Refactoring to a Better Design
image


image


image


image


image


image


image



Design Smells and Tips
image



image


image



image


image




The Dependency Inversion Principle


image


image



image


image


image


image



DEMO:The Problem

image


image


image


image


image


image



image



image



Refactoring to a Better Design
image



image



image



image



image



Design Smells
image



image



image



image


image




The Dependency Inversion Principle, Part 2

image


image



image


image



image



Traditional Programming
image


image



Refactoring Class Dependencies

First step is need to change the Static method to Instance method.
image


image


image


image


image


image


image


image


image


image

image




The Don't Repeat Yourself Principle, Part 1


image



image



image



Demo App and Analysis

image


image


image


image



image



Refactor Magic Strings
image



Refactoring Connection String

image

image


image


image



Refactoring Print Statements

image


image



Refactoring Magic Numbers
image


image



Refactoring Format Strings

image


image



Refactoring Duplicate Logic
image


image


image




Refactoring Repeated If-then Logic

image


image

image

image




Refactoring Conditional Polymorphism

image


image


image


image


image


image




The Don't Repeat Yourself Principle, Part 2


image



image



Test and Static Cling

image



image



Demo of Adding Integration Tests
image


image



Demo of Adding Unit Tests

image


image



image


image



Demo of MOCK Objects

image


image



image




Principles of Object Oriented Design - The Don't Repeat Yourself Principle, Part 3


image



Repeated Execution Pattern
image



Demo of Refactoring using Action of T

image


image



image



Demo of Refactor Data Access

image


image


image




Demo:  Find Duplicate Code – Atomiq

image

image



Code Generation
image



Repetition in process

image



Demo of Automation with MS Build

image


image


image


image


image


image








Dependency Inversion


image


image



Dependency Inversion


Introduction

image



image



image



image



image


image



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.

image


Copy program with DIP


image




Layering

image



image



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.

image


This below implementation is Loosely coupled, we could add more devices in that button if we implement below design.
image


image




Inversion of Control

image


image


image


image



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.
image


Here the Client boxing Match is creating IBoxer interface, all the low lever classes should implement this.

image



image



Flow Inversion
image


image



Creation Inversion
image


image



image


image


image



Dependency Injection


image



image



Below picture represent the Class with have all of its dependencies together.  Basically it does not implement dependency inversion.
image



Below picture represent the Class will get all of its dependencies from someone else like caterers.

image



image



Constructor Injection

image


image



Setting Injection
image


image



Interface Injection

image


image



image


image




Building an IoC Container


image


image



Visualizing Container

image


image



Demo of Manual Dependency Injection

image


image


image


image



Resolving Dependencies
image



Building the Real IOC Container

image


image


image


image


image


image



Using Unity

image



What is Unity?
image



Setting up Unity
image


image



Registering
image



Using the Container

image



image


Overriding Parameter

image


image



Controlling Life Cycle of Container Objects

Singleton Style

image



image



Using Castle Windsor


image



image



Setting up the Castle Windsor

image



image


image



Registering
image



Using the Castle Windsor
image



Controlling the Life Cycle of object

Singleton
image


image


Non Singleton

image


image


image



Using Structure Map

image


image



Setting up the Structure Map

image


image



image


image



Registering
image



Using the Container
image



Controlling Life Cycle

Not Singleton

image


image



Singleton

image


image


image


image



Using Ninject
image



What is Ninject
image



Setting up Ninject

image


image


image



Registering
image



Using the Container

image


image


image



Controlling Life Cycle

Non Singleton

image


image


Singleton

image


image


image









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