Mapping Design to Code
Mapping Design to Code
language.
(or)
Explain about the implementation model.
(or)
Explain in detail the design artifacts to implementation code in an object oriented language.
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.
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.
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.
The sequence of messages in an interaction diagram translates to series of statements in the method
definitions.
Message 2:
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 2 Create concrete bridge implementer classes implementing the DrawAPI interface.
Step 5 Use the Shape and DrawAPI classes to draw different colored circles.
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 4 Use the Context to see change in behaviour when it changes its Strategy.
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