Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Object Design Examples with GRASP
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
BTS530: Major Project Planning and Design Iterative Development References: Agile & Iterative Development, by Craig Larman, 2004, Addison Wesley. Agile.
Chapter 21 Test Driven development. TDD Write the test first Show that test fails Write code to pass the test Run whole suite of tests! This is unit testing.
Oct Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object.
March Ron McFadyen1 Ch 17: Use Case Realizations with GRASP Patterns Assigning responsibilities to objects to achieve user goals Section 17.4.
Fall 2009AXS-3913 Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object.
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Oct Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object.
Object-Oriented Analysis and Design
NJIT Designing for Visibility Chapter 19 Applying UML and Patterns Craig Larman.
November Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object.
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
Object-Oriented Analysis and Design
Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative Development Part III Elaboration Iteration I – Basic1.
Object-Oriented Design. From Analysis to Design Analysis Artifacts –Essential use cases What are the problem domain processes? –Conceptual Model What.
Object Oriented Software Development
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Writing Classes (Chapter 4)
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Systems Analysis and Design in a Changing World, 3rd Edition
Refactoring1 Improving the structure of existing code.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Chapter 21 Test-Driven Development 1CS6359 Fall 2011 John Cole.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
OO Methodology Elaboration Iteration 2 - Design Patterns -
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Chapter 5 Introduction to Defining Classes
Object-Oriented Analysis and Design Week 11, 2009.
Object Oriented Analysis and Design 1 Chapter 9 From Design to Implementation  Implementation Model  Forward, Reverse, and Round-Trip Engineering  Mapping.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
OO Methodology Elaboration Phase Iteration 1- Part 3.
Refactoring1 Improving the structure of existing code.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Topic: Junit Presenters: Govindaramanujam, Sama & Jansen, Erwin.
Use-Case Model: Adding Detail with Operation Contracts.
Design Model: Determining Visibility CH-18. Objectives Identify four kinds of visibility. Design to establish visibility. Illustrate kinds of visibility.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Mapping Designs to Code. It specify how to map the design into object oriented language The UML artifacts created during the design work, the interaction.
Module Road Map Refactoring Why Refactoring? Examples
GRASP: Visibility and Design
Computer Science 209 Testing With JUnit.
Overview of Eclipse Lectures
Test Driven development
Test Driven development
Chapter 10: Visibility Chapter 18 in Applying UML and Patterns Book.
Chapter 20 Applying UML and Patterns Craig Larman
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Improving the structure of existing code
Chapter 11: Class Diagram
Chapter 16 UML Class Diagrams
Corresponds with Chapter 5
Refactoring.
Chapter 11: Class Diagram
Presentation transcript:

Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative Development Part III Elaboration Iteration I – Basic 3

Software Engineering 2 Object-oriented Analysis and Design Chap 19 Designing for Visibility

Software Engineering 3 Object-oriented Analysis and Design Visibility Between Objects 1  System operations illustrate messages between objects. m A sender object send a message to a receiver object, the sender must be visible to the receiver. m Sender must have some kind of reference or pointer to the receiver object. m e.g., the getProductDescription message sent from a Register to a ProductCatalog implies that the ProductCatalog instance is visible to the Register instance.

Software Engineering 4 Object-oriented Analysis and Design  Visibility from the Register to ProductCatalog is required Visibility Between Objects 2

Software Engineering 5 Object-oriented Analysis and Design Visibility 1  Visibility Visibility m is the ability of an object to "see" or have a reference to another object. m One instance is within the scope of another.  Visibility types m Attribute visibility: B is an attribute of A. m Parameter visibility: B is a parameter of a method of A. m Local visibility: B is a (non-parameter) local object in a method of A. m Global visibility: B is in some way globally visible.

Software Engineering 6 Object-oriented Analysis and Design Visibility 2  Attribute visibility B is an attribute of A. m It is a relatively permanent visibility because it persists as long as A and B exist. m A Register instance may have attribute visibility to a ProductCatalog, since it is an attribute of the Register. :Register enterItem (itemID, quantity) :ProductCatalog public void enterItem(itemIDqty) { …. desc=catalog.getProductDes(itemID) …. } class Register {... private ProductCatalog catalog;... } desc=catalog.getProductDes(itemID)

Software Engineering 7 Object-oriented Analysis and Design Visibility 3  Parameter Visibility from A to B m when B is passed as a parameter to a method of A. m It is a relatively temporary visibility because it persists only within the scope of the method. m when the makeLineItem message is sent to a Sale instance, a ProductDescription instance is passed as a parameter. 2:makeLineItem(desc,qty) enterItem(id,qty) 1:desc=getProductDesc(id) 2.1:create(desc,qty) :Register:Sale :Product Catalog sl:SalesLineItem makeLineItem(ProductDescription desc,int qty) {... sl=new SalesLineItem(desc,qty);... }

Software Engineering 8 Object-oriented Analysis and Design Visibility 4 m transform parameter visibility into attribute visibility.  When the Sale creates a new SalesLineItem, it passes the ProductDescription in to its constructor.constructor  the parameter is assigned to an attribute, thus establishing attribute visibility. 2:makeLineItem(desc,qty) enterItem(id,qty) 2:desc=getProductDesc(id) 2.1:create(desc,qty) :Register:Sale :Product Catalog sl:SalesLineItem //initializing method(e.g.,a Java constructor) SalesLineItem(ProductDescription desc,int qty) {... description=desc;//parameter to attribute visibility... }

Software Engineering 9 Object-oriented Analysis and Design Visibility 5  Local Visibility from A to B exists m when B is declared as a local object within a method of A. m It is a relatively temporary visibility. m Two means by which local visibility is achieved  Create a new local instance and assign it to a local variable.  Assign the returning object from a method invocation to a local variable (enterItem method of class Register).  // there is implicit local visibility to the foo object  // returned via the getFoo call  anObject.getFoo().doBar();  To transform locally declared visibility into attribute visibility.

Software Engineering 10 Object-oriented Analysis and Design Visibility 5

Software Engineering 11 Object-oriented Analysis and Design Visibility 6  Global Visibility from A to B exists m when B is global to A. m It is a relatively permanent visibility  To achieve global visibility m to assign an instance to a global variable, such as C++.

Software Engineering 12 Object-oriented Analysis and Design Chap 20 Mapping Designs to Code

Software Engineering 13 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring

Software Engineering 14 Object-oriented Analysis and Design Test-Driven Development 1  The test is written first, imagining the code to be tested is written.  Advantages include m The unit tests actually get written m Programmer satisfaction leading to more consistent test  The psychological aspects of development can't be ignored programming is a human endeavor. m Clarification of detailed interface and behavior  That reflection improves or clarifies the detailed design. m Provable, repeatable, automated verification m The confidence to change things  When a developer needs to change existing code written by themselves, there is a unit test suite that can be run, providing immediate feedback if the change caused an error.

Software Engineering 15 Object-oriented Analysis and Design Test-Driven Development 2  The popular unit testing framework is the xUnit family m For Java, the popular version is JUnit. NUnit for.NET m JUnit is integrated into most of the Java IDEs, such as Eclipse.  Example fo Sale class, write a unit testing method in a SaleTest class m Create a Salethe thing to be tested (also known as the fixture). m Add some line items to it with the makeLineItem method (the makeLineItem method is the public method we wish to test). m Ask for the total, and verify that it is the expected value, using the assertTrue method. JUnit will indicate a failure if any assertTrue statement does not evaluate to true.  Each testing method follows this pattern: m Create the fixture. m Do something to it (some operation that you want to test). m Evaluate that the results are as expected.

Software Engineering 16 Object-oriented Analysis and Design Test-Driven Development 3  To use JUnit, to create a test class that extends the JUnit TestCase class; the test class inherits various unit testing behaviors. m create a separate testing method for each Sale method. m write unit testing methods for each public method of the Sale class.  To test method doFoo, it is an idiom to name the testing method testDoFoo. public class SaleTest extends TestCase { // … // test the Sale.makeLineItem method public void testMakeLineItem() { // STEP 1: CREATE THE FIXTURE // -this is the object to test // -it is an idiom to name it 'fixture' // -it is often defined as an instance field rather than // a local variable Sale fixture = new Sale(); // set up supporting objects for the test Money total = new Money( 7.5 ); Money price = new Money( 2.5 );

Software Engineering 17 Object-oriented Analysis and Design Test-Driven Development 4 ItemID id = new ItemID( 1 ); ProductDescription desc = new ProductDescription( id, price, "product 1" ); // STEP 2: EXECUTE THE METHOD TO TEST // NOTE: We write this code **imagining** there // is a makeLineItem method. This act of imagination // as we write the test tends to improve or clarify // our understanding of the detailed interface to // to the object. Thus TDD has the side-benefit of // clarifying the detailed object design. // test makeLineItem sale.makeLineItem( desc, 1 ); sale.makeLineItem( desc, 2 ); // STEP 3: EVALUATE THE RESULTS // there could be many assertTrue statements // for a complex evaluation // verify the total is 7.5 assertTrue( sale.getTotal().equals( total )); }

Software Engineering 18 Object-oriented Analysis and Design Refactoring 1  Refactoring m is a structured, disciplined method to rewrite or restructure existing code without changing its external behavior, applying small transformation steps combined with re- executing tests each step.  The essence of refactoring m applying small behavior preserving transformations (each called a 'refactoring'), one at a time. m After each transformation, the unit tests are re-executed to prove that the refactoring did not cause a regression (failure).

Software Engineering 19 Object-oriented Analysis and Design Refactoring 2  The activities and goals refactoring m remove duplicate code m improve clarity m make long methods shorter m remove the use of hard-coded literal constants  Some code smells include m duplicated code m big method m class with many instance variables m class with lots of code m strikingly similar subclasses m little or no use of interfaces in the design m high coupling between many objects

Software Engineering 20 Object-oriented Analysis and Design In Java, for example, replace using the new operator and constructor call with invoking a helper method that creates the object (hiding the details). Replace Constructor Call with Factory Method Put the result of the expression, or parts of the expression, in a temporary variable with a name that explains the purpose. Introduce Explaining Variable (specialization of Extract Local Variable) Replace a literal constant with a constant variable.Extract Constant Transform a long method into a shorter one by factoring out a portion into a private helper method. Extract Method DescriptionRefactoring Refactoring 3  Refactorings example

Software Engineering 21 Object-oriented Analysis and Design Refactoring 4  Before introducing an explaining variable. // good method name, but the logic of the body is not clear boolean isLeapYear( int year ) { return( ( ( year % 400 ) == 0 ) || ( ( ( year % 4 ) == 0 ) && ( ( year % 100 ) != 0 ) ) ); }  After introducing an explaining variable. // that's better! boolean isLeapYear( int year ) { boolean isFourthYear = ( ( year % 4 ) == 0 ); boolean isHundrethYear = ( ( year % 100 ) == 0); boolean is4HundrethYear = ( ( year % 400 ) == 0); return(is4HundrethYear||(isFourthYear&& !isHundrethYear)); }  IDE Support for Refactoring: Eclipse IDE