SOEN 343 Software Design

  • View

  • Download

Embed Size (px)


SOEN 343 Software Design. Section H Fall 2006 Dr Greg Butler Responsibilities, Principles, Patterns. Design Good Design, Smells, Evolutionary Design TDD (Test Driven Design) RDD (Responsibility Driven Design) GRASP Principles - PowerPoint PPT Presentation

Text of SOEN 343 Software Design

  • SOEN 343Software DesignSection H Fall 2006Dr Greg Butler

  • Responsibilities, Principles, PatternsDesignGood Design, Smells, Evolutionary Design

    TDD (Test Driven Design)

    RDD (Responsibility Driven Design)

    GRASP PrinciplesInformation Expert, Creator, Polymorphism

  • What is Design?Developing a blueprint (plan) for a mechanism that performs the required task,

    taking into account all the constraints, &

    making trade-offs between constraints when they are in conflict.

  • Design vs. Requirements and Implementation.Requirements



  • Design LevelsArchitectural design...Detailed design...Implementation (executable designs)

  • Two complimentary approaches to designPlanned Design vs. Evolutionary Design

    Can we get away with only planned design?

  • Evolutionary DesignWhat is the probability that a S/W design will need to be updated?Change is inevitable, evolutionary design recognizes this.As software is changed, generally it becomes more complex unless effort is made to keep it simple.

  • Evolutionary DesignPracticesXPTest driven development (TDD)Do not add code unless you have a test failing Important characteristicsFull automated test suitesRefactoringHelp us learn detailed design idioms, patterns,

  • Prerequisites to Successful Evolutionary Design?Testing lots of automated testing.Refactoring keeping the design simple.Continuous integration

    Actually, testing is a prerequisite to refactoring.

  • RefactoringA refactoring is a change made to the internal structure of S/W to make it easier to understand and less expensive to modify, without changing its observable behavior.

  • Can you pick out a good design?What is a good design?Satisfies user needs.Is a simple as possible. Kent Beck:Runs all testsReveals intention.No duplication.Fewest number of classes or methods can you smell bad design choices?

  • Bad SmellsDuplication.Long method.we will be learning more.

  • Test Driven DesignWrite tests first.Why does it make sense to write tests first?

    TDD in its pure formDo not add any (product) code unless a test failing.

  • Test Driven DesignEnabling technologies*Unit, e.g.JUnit

  • JUnit Basics: TestCase ClassIs a container for related test cases, not just one test case.Usage: subclass TestCase.E.g.

    public class MovieTest extends junit.framework.TestCase{ }

  • TestCase Clase Usage: Test MethodsWrite a method for each test.Method should be declared public void.Convention: method name starts with testpublic void testGetTitle().

    By following the naming convention, individual tests will be picked up automatically (by reflection).

  • A Test That Always Failspublic void testFailure() {fail();}Yieldsjunit.framework.AssertionFailedErrorat MovieTest.testFailure( java.lang.reflect.Method.invoke(Native Method)

  • Most Common: Testing For Expected Valuespublic void testEmptyVectorSize() {Vector v = new Vector();assertEquals( size should be 0, // msg 0, // expected valuev.size()// actual value);}

  • Other Assert MethodsassertEquals(expected_value, actual_value)i.e. no message provided.assertNull(reference_type_expr)assertNotNull(reference_type_expr)assertTrue(boolean_expr)assertFalse(boolean_expr)assertSame(expected_ref, actual_ref)

  • JUnit Example, VectorTest Classimport junit.framework.TestCase;public class VectorTest extends TestCase {public void testEmptyVectorSize() {Vector v = new Vector();assertEquals(0, v.size());}}

  • What is OO Analysis and DesignObject-Oriented Analysis

    Important domain concepts or objects?


    Visualized in the UP Domain Model

    Object-Oriented Design

    Design of software objects


    Design patterns

    Visualized in the UP Design Model

  • Responsibility-Driven Design (RDD)Detailed object design is usually done from the point of view of the metaphor of:Objects have responsibilitiesObjects collaborateResponsibilities are an abstraction.The responsibility for persistence.Large-grained responsibility.The responsibility for the sales tax calculation.More fine-grained responsibility.

  • The 9 GRASP PrinciplesCreatorExpertControllerLow CouplingHigh CohesionPolymorphismPure FabricationIndirectionProtected Variations

  • Object ResponsibilitiesA responsibility is an obligation of an object in terms of its behavior.

    (More on this later)

  • Design: Larmans ApproachMethodology based onResponsibility assignment.GRASP General Responsibility Assignment Software Patterns.Input:Use cases.Domain model.Operation contracts.Larman, Chapter 17.

  • Information Expert expresses the common intuition that objects do things related to the information they have.Assign the responsibility for knowing [something] to the object (class) that has the information necessary to fulfill the responsibility.

  • CreatorAssign to class B the responsibility to create an instance of class A ifB aggregates A objects.B contains A objects.B records instances of A objects.B closely uses A objects.B has the initializing data that will be passed to A when it is created.

  • Farm Class Diagram- animals

  • Test Casespackage farm.tests;public class FarmTest extends {

    public void testGetNumLegs() { Farm f = new Farm(); f.add(new Animal("Duck", "Donald")); assertEquals(2, f.getNumLegs()); f.add(new Animal("Dog", "Pluto")); assertEquals(6, f.getNumLegs());}}

  • Animal Classpublic class Animal {private String name;private String kind;public Animal(String aKind, String aName) {kind = aKind;name = aName;}public String getKind() {return kind;}

  • Farm Class, public int getNumLegs() { int result = 0;Iterator it = animals.iterator();while(it.hasNext()) {Animal a = (Animal);if(a.getKind().equals("Duck")) {result += 2;} else if(a.getKind().equals( "Dog")) {result += 4;} else { // ?}}return result; }

  • Bad Smell in Farm.getNumLegs()?Can you fix it?Hints:By Information Expert, who should know about the number of legs of Animals, the Farm or ?Having cascaded ifs (or switch statements) over information from another class is usually a very bad smell in OO.Apply Larmans GRASP principles of Information Expert and Polymorphism.

  • GRASP: Polymorphism PrincipleLarman:When related alternatives or behaviors vary be type (class), assign responsibility for the behaviorusing polymorphic operationsto the types for which the behavior varies.(This principle was illustrated last week with the Animal hierarchy.)

  • Farm Example, Solution #1

  • Farm Example, Solution #2

  • Practice in TutorialApply Larmans GRASP principles of Information Expert and Polymorphism.

  • General Classification of Kinds of Responsibility To know.To do.To decide.

  • Responsibilities A Boat MetaphorWhat kind of responsibilities do each of the following objects have: To know.To do.To decide.

  • Responsibilities A Boat MetaphorKind of responsibility for:CaptainTo know?To do?To decide?

  • Responsibilities A Boat MetaphorKind of responsibility for:Navigator.To know?To do?To decide?

  • Responsibilities A Boat MetaphorKind of responsibility for:Compass.To know?To do?To decide?