How To Understand The Dependency Inversion Principle (Dip)



Similar documents
The Dependency Inversion Principle

OO Design Quality Metrics

Button, Button, Whose got the Button?

How To Use The Command Pattern In Java.Com (Programming) To Create A Program That Is Atomic And Is Not A Command Pattern (Programmer)


Embedded Real-Time Systems (TI-IRTS) State Machine Implementation

Project Development & Software Design

Patterns in. Lecture 2 GoF Design Patterns Creational. Sharif University of Technology. Department of Computer Engineering

Design with Reuse. Building software from reusable components. Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 14 Slide 1

Report on the Train Ticketing System

by Pearson Education, Inc. All Rights Reserved.

2. Advance Certificate Course in Information Technology

Tutorial on Writing Modular Programs in Scala

Server Virtualization with Windows Server Hyper-V and System Center

Short Introduction to Design Patterns

1. What are Data Structures? Introduction to Data Structures. 2. What will we Study? CITS2200 Data Structures and Algorithms

Konzepte objektorientierter Programmierung

Embedded Component Based Programming with DAVE 3

Introduction. General Course Information. Perspectives of the Computer. General Course Information (cont.) Operating Systems 1/12/2005

How to Write a Checker in 24 Hours

CS 101 Computer Programming and Utilization

Architecture & Design of Embedded Real-Time Systems (TI-AREM)

Chapter 1 Fundamentals of Java Programming

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Encapsulating Crosscutting Concerns in System Software

Software Life Cycle. Management of what to do in what order

Metastorm BPM Interwoven Integration. Process Mapping solutions. Metastorm BPM Interwoven Integration. Introduction. The solution

Lesson 06: Basics of Software Development (W02D2

Basics Series Basics Version 9.0

Application of UML in Real-Time Embedded Systems

Principles of Software Construction: Objects, Design, and Concurrency. Course Introduction. toad. toad Fall School of Computer Science

Brown County Information Technology Aberdeen, SD. Request for Proposals For Document Management Solution. Proposals Deadline: Submit proposals to:

Programming a Robot Using C++ Philipp Schrader & Tom Brown October 27, 2012

Merchant Warehouse Credit Card Integration Gym Assistant August 2009

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Chapter 1 - Forzip at a Glance

Galaxy Software Addendum

NOVA COLLEGE-WIDE COURSE CONTENT SUMMARY ITE INTRODUCTION TO COMPUTER APPLICATIONS & CONCEPTS (3 CR.)

Combining Mifare Card and agsxmpp to Construct a Secure Instant Messaging Software

Designing Event-Controlled Continuous Processing Systems Class 325

Ingegneria del Software Corso di Laurea in Informatica per il Management. Object Oriented Principles

Chain of Responsibility

COSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan

QUICK START GUIDE. Draft twice the documents in half the time starting now.

How To Draw A Cell Phone Into A Cellphone In Unminimal Diagram (Uml)

SysAidTM Freeware Installation Guide

BTEC First Diploma for IT. Scheme of Work for Computer Systems unit 3 (10 credit unit)

Procedure to Install Printer to the LifeWindow 6000 Rev 3.

Freescale Semiconductor, I

Binary storage of graphs and related data

COURSE OUTLINE COMPUTER INFORMATION SYSTEMS 1A. PREREQUISITE: None. Concurrent enrollment in CIS-96 or CIS-97 is recommended.


How to Create a Resume Using Microsoft Word

Discover Live Network

PROXIMITY CARD READERS C-10, C-20, C60, C70

Singletons. The Singleton Design Pattern using Rhapsody in,c

Building native mobile apps for Digital Factory

Linux Driver Devices. Why, When, Which, How?

CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Service Oriented Architecture for Agricultural Vehicles

User Manual Network connection and Mobics Dashboard (MIS) software for Dryer Controller M720

Document Management Solutions

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Compact Contact Center (CCC)

Nintex Workflow 2013 & InfoPath Form Design workshop

PHP Code Design. The data structure of a relational database can be represented with a Data Model diagram, also called an Entity-Relation diagram.

EcgSoft. Software Developer s Guide to RestEcg. Innovative ECG Software info@ecg-soft.com

Construction Principles and Design Patterns. Flyweight, Bridge, Builder

What do you think? Definitions of Quality

Tutorial: Getting Started

Client Overview. Engagement Situation. Key Requirements

Application Architectures

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

SysAid Freeware Installation Guide

Design Patterns. Advanced Software Paradigms (A. Bellaachia) 1

ELFRING FONTS INC. MICR FONTS FOR WINDOWS

Point-of-Sale Updates Training Guide. Product Name: Point-of-Sale Release Version: 6.0

CLAS12 Offline Software Tools. G.Gavalian (Jlab)

6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang

Linux Kernel Architecture

Using the CoreSight ITM for debug and testing in RTX applications

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

Installing, Configuring and Administering Microsoft Windows

AN INTELLIGENT TUTORING SYSTEM FOR LEARNING DESIGN PATTERNS

Syllabus for CS 134 Java Programming

Software Engineering: Analysis and Design - CSE3308

Chapter 6: Project Planning & Production

The How Do Guide to AxioVision. Author: Brian Svedberg Image Analysis Specialist Carl Zeiss MicroImaging, Inc.

Transcription:

Embedded Real-Time Systems (TI-IRTS) General Design Principles 1 DIP The Dependency Inversion Principle Version: 22-2-2010

Dependency Inversion principle (DIP) DIP: A. High level modules should not depend upon low level modules. Both should depend upon abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions. Ref. The Dependency Inversion Principle, article by Robert C. Martin Slide 2

The Copy program (1) copy read Keyboard Structure chart write Printer void copy() // a C function { int c; while ( (c=readkeyboard())!= EOF) writeprinter(c); } Slide 3

The Enhanced Copy program (2) Changed requirement: The output should be either to a printer or to a disk enum OutputDevice {printer, disk}; void copy(outputdevice dev) { int c; while ( (c=readkeyboard())!= EOF) if (dev== printer) writeprinter(c); else writedisk(c); } The problem is that the high level policy i.e. the Copy module is dependent upon the low level detailed modules it controls. Slide 4

The OO Copy program (3) Copy Reader Notice: abstract classes Writer Keyboard Reader Printer Writer The dependency has been inverted! The copy class depends upon abstractions, and the detailed reader and writer depends upon the same abstractions Slide 5

The OO Copy program (4) class Reader { public: virtual int read() = 0; // pure virtual operation }; class Writer { public: virtual void write(char ch) = 0; // pure virtual operation }; void Copy(Reader& r, Writer& w) { int c; while ( (c=r.read())!= EOF) w.write(c); } Slide 6

Layering Simple Layers Policy Layer Mechanism Layer Utility Layer NB! The dependency is transitive Slide 7

Layering Abstract Layers Policy Layer Mechanism Interface Mechanism Layer Utility Interface NB! no transitive or direct dependency between layers Utility Layer Slide 8

An Inversion of Ownership Notice: inversion is also an inversion of ownership We often think of utility libraries as owning their own interfaces With DIP: The clients own the abstract interfaces The servers derives from them Known as the Hollywood principle: Don t call us, we ll call you Slide 9

Inverted Layers Policy Policy Layer «interface» Mechanism Interface Mechanism Mechanism Layer «interface» Utility Interface Utility Utility Layer Slide 10

A Simple Example (DIP) Dependency inversion can be applied where ever one object sends a message to another Button +Button(Lamp& l) +Detect() itslamp Lamp +TurnOn() +TurnOff() void Button::Detect() { bool buttonon= GetPhysicalState(); if (buttonon) itslamp->turnon(); else itslamp->turnoff(); } Slide 11

Example: Inverted Button Model Button +Detect(): void +GetState(): bool ButtonClient +TurnOn(): void +TurnOff(): void Reusable Button Implementation Button Imp.2 Lamp Motor +Detect(): void +GetState(): bool +TurnOn(): void +TurnOff(): void +TurnOn(): void +TurnOff(): void Slide 12

Template Method (GoF Pattern) The GoF Template method is a good example of DIP In this pattern a high level algorithm is encoded in an abstract base class and makes use of pure virtual functions to implements its details Derived classes implements those detailed virtual functions Thus, the class containing the details depends upon the class containing the abstraction Slide 13

Template Method - GoF Structure AbstractClass TemplateMethod() PrimitiveOperation1() PrimitiveOperation(2) // Common code PrimitiveOperation1() // more common code // PrimitiveOperation2() // ConcreteClass PrimitiveOperation1() PrimitiveOperation2() Notice: The Template Method is concrete Ref. GoF Design Patterns, Gamma et. al Slide 14

DIP - conclusion The principle of dependency inversion is at the root of many of the benefits claimed for object-oriented technology. Its proper application is necessary for the creation of reusable frameworks It is also critically important for the construction of code that is resilient to change Slide 15