MAPPING DESIGNS TO CODE Atoi Software System Bangalore  [email_address]
Objectives: Map design artifacts to code in an OO- language(JAVA). Introduction: The UML artifacts created during the design phase – collaboration diagrams and design class diagrams – will be used as input to the code generation process. In ROSE – you need only Class Diagram .
Mapping Designs to Code: Public class SalesLineItem { Public SalesLineItem(ProductSpecification spec,int qty); Public float subtotal(); Private int quantity; } Note  the addition of the Java Constructor SalesLineItem(…) is derived From the fact that a create(spec,qty) message is sent to a SalesLineItem In the enter item collaboration diagram.
Adding Reference Attributes A reference attribute is an attribute that referes to another complex object, not to a primitive type such as a string, Number, and so on. The Reference attributes of a class are suggested by the associations and navigability in a class diagram Public class SalesLineItem { public SalesLineItem(ProductSpecification spec,int qty); public float subtotal(); private int quantity; private ProductSpecification prodSpec; } // simple attribute //Reference attribute
Reference Attributes & Role Name Role name  is a name that identifies the role and often provides some semantic context as the nature of the role. If Role name is present in a class diagram , use it as the basis for the name of the reference attribute  during code generation. prodSpec Public class SalesLineItem { public SalesLineItem(ProductSpecification spec,int qty); public float subtotal(); private int quantity; private ProductSpecification prodSpec; } // simple attribute //Reference attribute
Writing Methods with help of collaboration Diagram The sequence of messages shown in the collaboration diagram will be translated to a series of statements in the method definition. Nest Slide>>>
POST – enterItem Method public class POST { public POST(ProductCatalog pc); public void endSale(); public void enterItem(int upc,int qty); public void makePayment(float cashTendered); Private ProductCatalog prodCatalog; // reference attributes Private Sale sale; } Public Void enterItem( int upc, int qty)  Message 1  (create sale if new)>> if(isNewSale()){ sale = new Sale();} Message 2  send getspec for catalog to retrieve productspec ProductSpecification spec =    productCatalog.specification(upc); Message 3  : send makelineItem to sale Sale.makeLineItem(spec,qty)
The POST – isNewSale Method Note this isNewSale this was not mentioned anywhere in our collaboration diagram but during coding phase changes form the design will appear ( which is inevitable and natural ), but keep in mind to make changes in the related artifacts and document the changes thoroughly. private boolean isNewSale() { return ( sale == null) || ( sale.isComplete() ); }
Sale – makeLineItem Method Public void makeLineItem(ProductSpecification spec, int qty) {  // implementation of message 4.1 and 4.2 lineItem.addElements(new SaleLineItem(spec,qty); }

(OOAD) UML Slides

  • 1.
    MAPPING DESIGNS TOCODE Atoi Software System Bangalore [email_address]
  • 2.
    Objectives: Map designartifacts to code in an OO- language(JAVA). Introduction: The UML artifacts created during the design phase – collaboration diagrams and design class diagrams – will be used as input to the code generation process. In ROSE – you need only Class Diagram .
  • 3.
    Mapping Designs toCode: Public class SalesLineItem { Public SalesLineItem(ProductSpecification spec,int qty); Public float subtotal(); Private int quantity; } Note the addition of the Java Constructor SalesLineItem(…) is derived From the fact that a create(spec,qty) message is sent to a SalesLineItem In the enter item collaboration diagram.
  • 4.
    Adding Reference AttributesA reference attribute is an attribute that referes to another complex object, not to a primitive type such as a string, Number, and so on. The Reference attributes of a class are suggested by the associations and navigability in a class diagram Public class SalesLineItem { public SalesLineItem(ProductSpecification spec,int qty); public float subtotal(); private int quantity; private ProductSpecification prodSpec; } // simple attribute //Reference attribute
  • 5.
    Reference Attributes &Role Name Role name is a name that identifies the role and often provides some semantic context as the nature of the role. If Role name is present in a class diagram , use it as the basis for the name of the reference attribute during code generation. prodSpec Public class SalesLineItem { public SalesLineItem(ProductSpecification spec,int qty); public float subtotal(); private int quantity; private ProductSpecification prodSpec; } // simple attribute //Reference attribute
  • 6.
    Writing Methods withhelp of collaboration Diagram The sequence of messages shown in the collaboration diagram will be translated to a series of statements in the method definition. Nest Slide>>>
  • 7.
    POST – enterItemMethod public class POST { public POST(ProductCatalog pc); public void endSale(); public void enterItem(int upc,int qty); public void makePayment(float cashTendered); Private ProductCatalog prodCatalog; // reference attributes Private Sale sale; } Public Void enterItem( int upc, int qty) Message 1 (create sale if new)>> if(isNewSale()){ sale = new Sale();} Message 2 send getspec for catalog to retrieve productspec ProductSpecification spec = productCatalog.specification(upc); Message 3 : send makelineItem to sale Sale.makeLineItem(spec,qty)
  • 8.
    The POST –isNewSale Method Note this isNewSale this was not mentioned anywhere in our collaboration diagram but during coding phase changes form the design will appear ( which is inevitable and natural ), but keep in mind to make changes in the related artifacts and document the changes thoroughly. private boolean isNewSale() { return ( sale == null) || ( sale.isComplete() ); }
  • 9.
    Sale – makeLineItemMethod Public void makeLineItem(ProductSpecification spec, int qty) { // implementation of message 4.1 and 4.2 lineItem.addElements(new SaleLineItem(spec,qty); }