Setting up for TTD in Visual Studio 2012 Project | Manage NuGet Packages Select the online tab Search for Nunit Select the Nunit package Follow these instructions.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Inheritance Inheritance Reserved word protected Reserved word super
Chapter 10: Introduction to Inheritance
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Object-oriented Programming Concepts
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Inheritance using Java
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
Design Patterns.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Abstract Factory Design Pattern making abstract things.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Tech Talk Go4 Factory Patterns Presented By: Matt Wilson.
Programming Pillars Introduction to Object- Oriented Programming.
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
Computing IV Singleton Pattern Xinwen Fu.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
CLASSES AND OBJECTS Chapter 3 : constructor, Separate files, validating data.
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
C++ How to Program, 7/e.  There are cases in which it’s useful to define classes from which you never intend to instantiate any objects.  Such classes.
Factory Method. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Advanced Programming in Java
Advanced Programming in Java
Unit II-Chapter No. : 5- design Patterns
Lecture 12 Inheritance.
Factory Patterns 1.
Interface, Subclass, and Abstract Class Review
03/10/14 Inheritance-2.
Software Design and Architecture
Programming Design Patterns
Software Engineering Lecture 7 - Design Patterns
Object-Oriented Programming
Advanced Programming in Java
Object-Oriented Programming
Advanced Programming in Java
Object-Oriented Programming
CIS 199 Final Review.
Dependency Inversion principle
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Presentation transcript:

Setting up for TTD in Visual Studio 2012 Project | Manage NuGet Packages Select the online tab Search for Nunit Select the Nunit package Follow these instructions to download and install the Nunit test adapter:

Setting up for TDD in Eclipse See steps 4 and 5 in this tutorial: junit-testing/ junit-testing/

Reducing Dependency

Class Interdependency When one class depends on another there are undesirable consequences It is more difficult to reuse the dependent class It is more difficult to maintain the dependent class It is more difficult to test the dependent class

Class Dependency Class A is said to be dependent on class B when class B is required for class A’s specification or implementation. Example: class Car { : private: Engine theEngine; }; The Car class depends on the Engine class.

UML Indication of dependency The Car class depends on the Engine class

We will try to remove dependencies when practical We can remove a dependency on a class by changing it to a dependency on an interface. Car can now use any propulsion system that implements the interface “Propulsion System”

Car class is much more extensible now.

It is also easier to test! We can write fakes classes that implement Propulsion System for unit tests.

We broke an interclass dependency using an interface Benefits Car can now have any engine that implements the Propulsion System interface As new engines are developed, we can use them in Car – provided that the new engines implement the Propulsion System Interface. This makes Car easier to test, because we can make fake classes that implement Propulsion System.

Dependency Inversion Principle Depend upon abstractions: Do not depend upon concrete classes. Code to interfaces – not class definitions. High-level components should not depend on low-level components Both high-level and low-level classes should depend on abstractions.

Guidelines for reducing Dependencies (Head-first Design Patterns) Beware of variables that hold references to concrete classes Beware of classes that derive from concrete classes Beware of classes that override an implemented member function in a base classes Because the subclass is relying on a concrete class, not an abstraction.

Interfaces in C ++ // In C ++ we can implement interfaces as abstract base classes // in which all member functions are public pure virtual. class PropulsionSystem { public: // Request that the engine produce a certain amount of energy. virtual void requestBTU(float BTUs) = 0; // See how much energy the engine is currently producing virtual float getBTU() = 0; };

Instantiating the Propulsion Interface Method 1: Constructor Instantiation class Car { private: PropulsionSystem* propulsionSystem_; }; Car::Car(PropulsionSystem propulsionSystem) : propulsionSystem_(propulsionSystem) {} Car::~Car() { delete propulsionSystem_; }

Using Constructor Instantiation Car myCar(new InternalCombustionEngine()); Car myElectricCar(new ElectricEngine()); Car myTestCar(new FakeEngine()); /* The use of the interface provides flexibility; however, as soon as we say new we must refer to a concrete class and thus generate a dependency */

Instantiating the Propulsion Interface Method 2: getter/setter Instantiation class Car { public: setPropulsionSystem(PropulsionSystem* newSystem); private: PropulsionSystem* propulsionSystem_; }; // Usage Car myCar; myCar.setProulsionSystem(new ElectronicEngine());

A Simple Factory Classes Simple Factory class act like virtual constructors. You send the simple factory some information about your situation, and it returns the appropriate class. class SimplePropulsionFactory { public: static PropulsionSystem* createPropulsion(const string& reqs); };

Simple Factory createPropulsion PropulsionSystem* SimplePropulsionFactory::createPropulsion(const string& req) { PropulsionSystem* prop = 0; if(string == “green”) prop = new ElectricEngine(); if (string == “fast”) prop = new InternalCombustionEngine(); if (string == “test”) prop = new FakeEngine(); return prop; }

Instantiating the Propulsion class Method 3: Using a Simple Factory // Create a propulsion system using the factory – pass the // factory to the Car constructor. PropulsionSystem prop = SimpleFactory::createPropulsion(“green”); Car myCar(prop);

Method 4: Allow the subclasses to decide: Factory Method Pattern class Car { virtual void createPropulsion() = 0; }; class GreenCar : public Car { void createPropulsion() { propulsionSystem_ = new ElectricEngine(); } }

Method 5: The Abstract Factory Pattern The Abstract Factory Pattern provides an interface for creating families of related or dependent object without specifying their concrete classes. [Head First Design Patterns] There may be a number of things that vary from Car to Car Propulsion Systems Exhaust Systems Saftey Systems Create an interface for an abstract factory that produces each of the items that vary across Cars

CarCompnentFactory is an Example of the Abstract Factory Pattern class CarComponentFactory { public: PropulsionSystem* createPropulsion() = 0; ExhaustSystem* createExaustSystem() = 0; SafteySystem* createSaftySystem() = 0; }; class CaliforniaComponentFactory { // overrides abstract methods with concrete implementations } class EuropeanUnionComponentFactory { // overrides abstract methods with concrete implementations}