160 likes | 399 Views
Implementation Model: Mapping Designs To Code. Objectives. Map design artifacts to code in an object-oriented language With the completion of interaction diagrams and DCDs for the POS application, there is sufficient detail to generate code for the domain layer of objects.
E N D
Objectives • Map design artifacts to code in an object-oriented language • With the completion of interaction diagrams and DCDs for the POS application, there is sufficient detail to generate code for the domain layer of objects
Programming and the Development Process Suggestions: • For a two-week iteration, consider spending at least a half-day doing some visual modeling design work, before programming. Use simple "tools", such as a whiteboard. • Rational Rose is a fast, easy, and convenient, excellent tool to use • A strength of OOA/D and OO programming is that they provide an end-to-end roadmap from requirements through to code. • The various artifacts feed into later artifacts in a traceable and useful manner, ultimately culminating in a running application
Creativity and Change During Implementation • Realistically, the design is an incomplete first step; during programming and testing, changes will be made and detailed problems will be uncovered and resolved • Done well, the design artifacts will provide a resilient core that scales up with elegance and robustness to meet the new problems encountered during programming
Case Study: Map the POS Design to Java Creating Class Definitions from DCDs • DCDs describe the class or interface name, superclasses, method signatures, and simple attributes of a class. Use them to create a basic class definition in an object-oriented programming language
Continue - Add Reference Attributes • A reference attribute is an attribute that refers to another complex object, not to a primitive type such as a String, Number. • The reference attributes of a class are suggested by the associations and navigability in a class diagram
Continue - Create Methods from Interaction Diagrams • An interaction diagram shows the messages that are sent in response to a method invocation
Container/Collection Classes in Code • The choice of collection class is of course influenced by the requirements; key-based lookup requires the use of a Map, a growing ordered list requires a List, and so on
Exceptions and Error Handling • Exception handling has been ignored so far in the development of a solution. This was intentional to focus on the basic questions of responsibility assignment and object design
Order of Implementation • Classes need to be implemented from least-coupled to most-coupled • Ie. from those having least dependencies to having most dependencies
Case Study: Writing the Unit Test Stub for Sale • Beforeprogramming the Saleclass, write a unit testing method in a SaleTestclass that does the following: • 1. Set up a new sale • 2. Add some line items to it • 3. Ask for the total, and verify it is the expected value • Code: public class SaleTest extends TestCase { // ... public void testTotal() { // set up the test Money total = new Money( 7 . 5 ); Money price = new Money( 2 . 5 ); ItemID id = new ItemID( 1 ); ProductSpecification spec; spec = new ProductSpecification( id, price, "product 1" ); Sale sale = new SaleO; // add the items sale.makeLineltern( spec, 1 ); sale.makeLineltern( spec, 2 ); // verify the total is 7 . 5 assertEquals( sale.getTotal(), total); } }