Creating Class Definitions from Design Class Diagrams: public class SalesLineItem // Java { private int quantity;

Similar documents
From designing to coding

Designing for Visibility & Mapping to Code CSSE 574: Session 4, Part 3

OO Design2. Design Artifacts

Mapping Designs to Code

COMP 6471 Software Design Methodologies

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

Some Software Engineering Techniques (Class Diagrams and Pair Programming)

Software Design and Analysis CSCI 2040

Download FirstOODesignPractice from SVN. A Software Engineering Technique: (Class Diagrams)

References: Applying UML and patterns Craig Larman

Constantinos Constantinides Computer Science and Software Engineering Concordia University Montreal, Canada

Information Expert (or Expert)

Software Modeling & Analysis

SE203b: OO Design for Software Engineers. Office: TEB349, Ext

CTIS 359 Principles of Software Engineering SOFTWARE DESIGN OO(A)D

Responsibilities. Using several specific design principles to guide OO design decisions.

Sequence Diagram. A UML diagram used to show how objects interact. Example:

What is a Model? Copyright hebley & Associates

Object Analysis & Design in the textbook. Introduction to GRASP: Assigning Responsibilities to Objects. Responsibility-Driven Design

Sequence Diagram. r: Register s: Sale

Assigning Responsibilities by Larman

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

CSCI 102 Fall 2010 Exam #1

COMP 6471 Software Design Methodologies

Design. Furthermore, it is natural to discover and change some requirements during the design and implementation work of the early iterations.

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

COMP 354: INTRODUCTION TO SOFTWARE ENGINEERING

Goal: build an object-oriented model of the realworld system (or imaginary world) Slicing the soup: OOA vs. OOD

And Even More and More C++ Fundamentals of Computer Science

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

Modeling Dynamic Behavior

Applying UML & Patterns (3 rd ed.) Chapter 15

Operations Contracts and Preliminaries on Design

Logical Architecture & Design Preliminaries

Chapter 3: Object Oriented Design

GRASP: Patterns for. chapter18

Modeling Dynamic Behavior

No Source Code. EEC 521: Software Engineering. Specification-Based Testing. Advantages

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 3

Domain Modeling- 2. Generalization

On to Object-oriented Design

10. Abstract Data Types

Black Box Testing. EEC 521: Software Engineering. Specification-Based Testing. No Source Code. Software Testing

Lab 12 Object Oriented Programming Dr. John Abraham

Tips from the experts: How to waste a lot of time on this assignment

CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class

4 Software models. often more than what people can handle not necessary to know all details at all times

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates

TOOLS AND TECHNIQUES FOR TEST-DRIVEN LEARNING IN CS1

CSE wi Midterm Exam 2/8/18. Name UW ID #

On to Object-oriented Design

CSSE 220 Day 3. Check out UnitTesting and WordGames from SVN

Copying Data. Contents. Steven J. Zeil. November 13, Destructors 2

Write for your audience

Tips from the experts: How to waste a lot of time on this assignment

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

VIRTUAL FUNCTIONS Chapter 10

Data & Procedure Java review

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Software Engineering Testing and Debugging Testing

Casting in C++ (intermediate level)

CPSC 427: Object-Oriented Programming

Software Testing. Software Testing. in the textbook. Chapter 8. Verification and Validation. Verification and Validation: Goals

This exam is open book. Each question is worth 3 points.

Advanced Systems Programming

Lab Exercise Test First using JUnit

Tools for Unit Test - JUnit

Agile Software Development. Lecture 7: Software Testing

Software Design and Analysis for Engineers

CSE wi Midterm Exam 2/8/18 Sample Solution

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

PART 5 Elaboration Iteration 3 Intermediate topics. Iteration 3

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

Tips from the experts: How to waste a lot of time on this assignment

Introduction to JUnit. Data Structures and Algorithms for Language Processing

Lab 2: ADT Design & Implementation

Tutorials for Struts, EJB, xdoclet and eclipse.

C++ Inheritance and Encapsulation

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Object Oriented Programming

Introduction to Programming Using Java (98-388)

Tips from the experts: How to waste a lot of time on this assignment

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

REPRESENTATION OF CLASS DIAGRAM AND SEQUENCE DIAGRAM IN PROCESS MODELING: UML-BASED STUDY

Tools for Unit Test JUnit

CMSC131. Library Classes

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

XNA Tutorials Utah State University Association for Computing Machinery XNA Special Interest Group RB Whitaker 21 December 2007

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli

CSC207 Week 3. Larry Zhang

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Extension Web Publishing 3 Lecture # 1. Chapter 6 Site Types and Architectures

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

CIT 590 Homework 10 Battleship

Outline. Logistics. Logistics. Principles of Software (CSCI 2600) Spring Logistics csci2600/

Transcription:

24.3.204 Coding (Implementation) The design model (design class diagram and interaction diagrams) provides some of the information that is necessary to generate the code. (Not all of the code) Creating Class Definitions from Design Class Diagrams: Basic attribute Reference (or pointer) public class slineitem // Java private int quantity; private ProductSpecification description; public slineitem(productspecification spec, int qty) public Money getsubtotal() slineitem - quantity : Integer + getsubtotal() : Money description ProductSpecification description : Text price : Money itemid : ItemID The addition of the constructor to the source code is derived from the create(spec, qty) message sent to a slineitem in the enteritem interaction diagram (see 5.5). 202 Dr. Feza BUZLUCA 6. Creating Methods from Interaction Diagrams: The sequence of the messages in an interaction diagram is mapped to statements in the method definitions. Example: The Register class and enteritem method public class Register private ProductCatalog catalog; private current; public Register(ProductCatalog pc) public void end() public void enteritem(itemid id, int qty) public void makenew() public void makepayment(money cashtendered) Register Register(pc: ProductCatalog, st:store) end() enteritem(id: ItemID, qty : Integer) makenew() makepayment(cashtendered : Money) catalog current ProductCatalog getspecification() makelineitem() makepayment() 202 Dr. Feza BUZLUCA 6.2

24.3.204 Example: The Register class and enteritem method (cont'd) Messages numbered as and 2 are mapped to statements in the enteritem method of the Register class. ProductSpecification spec = catalog.getspecification(id); current.makelineitem(spec, qty); enteritem(id, qty) :Register 2: makelineitem(spec, qty) : : spec := getspecification(id) :Product Catalog 202 Dr. Feza BUZLUCA 6.3 Collection Classes in Code: One-to-many relations implemented with the introduction of a collection object, such as a List, Map, or even a simple array. Example: LineItems in the. makelineitem() makepayment() lineitems slineitem quantity : Integer getsubtotal() public class private List<sLineItem> lineitems = new ArrayList()<sLineItem>; 202 Dr. Feza BUZLUCA 6.4 2

24.3.204 Store address : Address name : Text add() register.. Register end() enteritem() makenew() makepayment() 7 6 catalog current 0.. completeds ordered Order of Implementation Classes need to be implemented (and fully unit tested) from least-coupled to most-coupled. catalog ProductCatalog getspecification() makelineitem() makepayment() 5 3 descriptions Map.. lineitems ordered payment 202 Dr. Feza BUZLUCA ProductSpecification description : Text price : Money itemid : ItemID description slineitem quantity : Integer getsubtotal() Payment amount : Money 2 6.5 4 Test-Driven (Test-First) Development Unit testing: In object oriented programming classes are main individual components (units) of the program. So classes can (and must) be tested as individual units separately. In test-driven (or test-first) development, unit testing code is written before the code of the class to be tested, and the developer writes unit testing code nearly for all production code. The testing code should perform following operations: Creating (and deleting) objects of the class. (testing the constructor and destructor) Sending messages to objects and checking the results. Testing exceptional cases by sending parameters out of acceptable range. All of the testing code is not written once. The basic rhythm is to write a little test code, then write a little production (class) code, make it pass the test, then write some more test code, and so forth. Popular unit testing frameworks: Junit: Java, http://www.junit.org Nunit:.NET, http://www.nunit.org CruiseControl: Open Source http://cruisecontrol.sourceforge.net/ 202 Dr. Feza BUZLUCA 6.6 3

24.3.204 Advantages of test-first programming: It ensures that the unit tests are really written. Otherwise, programmers usually skip unit tests and left them as last work. Motivation (satisfaction) of programmers. In the traditional style (test-last development), a developer first writes the code of the class, informally debugs it, and then as an afterthought is expected to add unit tests, it doesn't feel satisfying. However, if the test is written first, we feel a challenge and question in front of us: Can I write code to pass this test? And then, after the code pass the tests, there is some feeling of success. It's human psychology. Clarification of detailed interface and behavior of the class. As you write the test code first you must imagine that the object code exists. You must think through the details of the public view of the method; its name, return value, parameters, and behavior. That improves the quality of the code. The confidence to change things. When a developer needs to change existing classes there is a unit test that can be run, providing immediate feedback if the change caused an error. 202 Dr. Feza BUZLUCA 6.7 Example: Unit test of the class Remember that we do not write all the unit tests for first; rather, we write only one test method, implement the solution in class to make it pass, and then repeat. Assume that we use the unit testing framework Junit. To use JUnit, you must create a test class that extends the JUnit TestCase class; your test class inherits various unit testing behaviors. Test code for the makelineitem meted of the class public class Test extends TestCase public void testmakelineitem() fixture = new (); // Tested object Money total = new Money(7.5); // Supporting objects Money price = new Money(2.5); ItemID id = new ItemID(); ProductSpecification spec = new ProductSpecification(id, price, product ); // Method is being tested fixture.makelineitem(spec, ); fixture.makelineitem(spec, 2); asserttrue( fixture..equals(total)); // Is the total calculated correctly? ::: 202 Dr. Feza BUZLUCA 6.8 4

24.3.204 Exceptions and Error Handling To focus on the responsibility assignment and object design, exception handling has been ignored so far in coding. However, in application development, exception handling strategies should be considered during design modeling and during implementation (coding). Coding Examples The code for the NextGen POS is generated from the design class diagrams and interaction diagrams defined in the design work. The given example codes define simple cases; they are not, fully developed programs with exception handling, and so on. Same programs are written in Java and C++. Please refer to following files. Java: NextGenPos_java.pdf C++: NextGenPos_cplusplus.pdf 202 Dr. Feza BUZLUCA 6.9 5