0% found this document useful (0 votes)
7 views

Mapping Design to Code

The document discusses the mapping of design to code implementation in object-oriented languages, emphasizing the use of class and interaction diagrams as inputs for code generation. It outlines the process of defining classes, methods, and reference attributes, as well as the implementation of collection classes. Additionally, it explains the Bridge and Strategy design patterns, detailing their structures and implementations, and concludes with important questions related to design principles and patterns.

Uploaded by

vedaraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Mapping Design to Code

The document discusses the mapping of design to code implementation in object-oriented languages, emphasizing the use of class and interaction diagrams as inputs for code generation. It outlines the process of defining classes, methods, and reference attributes, as well as the implementation of collection classes. Additionally, it explains the Bridge and Strategy design patterns, detailing their structures and implementations, and concludes with important questions related to design principles and patterns.

Uploaded by

vedaraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Explain in detail about the mapping of design to code implementation in an object oriented

language.
(or)
Explain about the implementation model.
(or)
Explain in detail the design artifacts to implementation code in an object oriented language.

Mapping design to code:

 The interaction diagram and class diagrams can be used as input to the code generation
process.
 Various object oriented languages such as Java++, C#, Small talk. Python and so on can be
used as the language of implementation.
 Implementation in an object oriented language requires writing source code for
 Class and interface definitions.
 Method Definitions.

Defining a Class with Methods and Simple Attributes

The class diagram consists of classes, interfaces, super classes, methods and attributes.
These elements are sufficient to create basic class definition in any object oriented language like java.
Mapping the methods and attributes from the class diagram is straight forward.

Adding Reference Attributes

A reference attribute is an attribute that refers to another complex object, not to a primitive type such
as a String, Number, and so on.
In this example, SalesLineItem that refers to a ProductSpecification instance.
Reference Attributes and Role Names
 Each end of an association is called a role.
 Role name is a name that identifies the role
 If a role name is present in a class diagram, use it as the name of the reference attribute during
code generation.

Creating Methods from Interaction Diagrams

The sequence of messages in an interaction diagram translates to series of statements in the method
definitions.

Here, enterItem, message is sent to register instance.

public void enterItem (int, ietmID, int qty)


Message 1:

A getProductDescription is sent to the Product catalog to retrieve Product Description.

ProductDescription desc = catalog.getProduct Description (itemID);

Message 2:

The makeLineItem message is sent to the sale.

CurrentSale.makeLineItem (desc, qty);

Collection Classes in Code

 The one to many relationship can be implemented as the collection object.


 The collection object can be Map, vector, List or Arrays.
 The java libraries consist of the collection classes such as Array List and Hash Map which
implements List and Map interfaces respectively.

Explain Bridge and Strategy Pattern in detail.

Bridge Pattern

 Bridge is used when we need to decouple an abstraction from its implementation so that
the two can vary independently.
 This type of design pattern comes under structural pattern as this pattern decouples
implementation class and abstract class by providing a bridge structure between them.
Implementation

Step 1 Create bridge implementer interface.

Step 2 Create concrete bridge implementer classes implementing the DrawAPI interface.

Step 3 Create an abstract class Shape using the DrawAPI interface.

Step 4 Create concrete class implementing the Shape interface.

Step 5 Use the Shape and DrawAPI classes to draw different colored circles.

Step 6 Verify the output.

Strategy Pattern:

In Strategy pattern, a class behavior or its algorithm can be changed at run time. This type of design
pattern comes under behavior pattern.

Implementation:

Create a Strategy interface defining an action and concrete strategy classes implementing the Strategy
interface. Context is a class which uses a Strategy. StrategyPatternDemo will use Context and strategy
objects to demonstrate change in Context behaviour based on strategy it deploys or uses.

Step 1 Create an interface.


Step 2 Create concrete classes implementing the same interface.

Step 3 Create Context Class.

Step 4 Use the Context to see change in behaviour when it changes its Strategy.

Step 5 Verify the output.

Important 2 Mark Questions with Answers

1. What is GRASP?

General Responsibility Assignment Software Patterns (or Principles) consists of guidelines for
assigning responsibility to classes and objects in object- oriented design.

2. What is responsibility?

The UML defines are responsibility as ―”a contract or obligation of a classifier”. Responsibilities are
related to the obligations or behavior of an object in terms of its role.

 Doing responsibility
 Knowing responsibility
3. What is design pattern?

A design pattern is a general reusable solution to a commonly occurring problem in software design.

 Creational patterns
 Structural patterns
 Behavioral patterns

4. Define patterns.

Pattern is a named description of a problem and solution that can be applied to new contexts; ideally,
it provides advice in how to apply it in varying circumstance

You might also like