Upload
ronald-baldwin
View
228
Download
0
Tags:
Embed Size (px)
Citation preview
Generation and Implementation
More on classes
• Types
• Implementation classes
• Interfaces
• Templates
• Associations– Dependencies– Compositions
Type classes
– are classes that are defined as a collection of operations without methods.
– They are used to model a collection of operations applicable to different classes of objects.
– are denoted as stereotyped class rectangles.– are equivalent to abstract classes with no method and
only abstract operations.– Must be stereotyped using the <<type>> keyword.– Are implemented by implementation classes.– May have generalisation relationships to other types.
‘AppleScript’ type classes
• AppleScript is a scripting system that allows you to directly control Macintosh applications
• It provides Unit Type value classes for working with measurements of length, area, cubic and liquid volume, mass, and temperature.
Unit Type value classes
Length Area Cubic volume
Liquid volume
Weight Temp-erature
Centi-metres
Square feet
Cubic feet Gallons Grams Degrees Celcius
Kilometres Square kilometres
Cubic yards
Litres Kilograms Degrees Fahrenheit
Feet Square Metres
Cubic metres
Quarts Ounces Degrees Kelvin
Inches Square miles
Cubic metres
Pounds
Metres
Miles
Implementation classes
– are denoted as stereotyped class rectangles.– Must be stereotyped using the <<implementation
class>> keyword.– May implement other classes via a ‘realises’
generalisation relationship from the implementation class to the implemented class.
• The implementation class inherits operations but not structure (attributes / associations)
– May also have generalisation relationships to other implementation classes.
Implementation classes
• These classes often do not relate to classes in the real-world domain.
• They are the ‘scaffolding’ classes that support the domain (boundary, control and entity) classes.
• An example would be a collection object to organise and maintain references to all objects in a collection. – This would be necessary to compile lists for scroll
boxes, aggregate derived fields, etc.
Interfaces
Interfaces
• These are classes that define a set of externally accessible operations without methods. They are used to model a collection of operations defining a service that may be offered by different classes.– Something like an external view in a database.
• Denoted as stereotyped class rectangles, or a small circles with the name of the interface attached.
interfaces
• Are equivalent to abstract classes with no attributes and no methods and only abstract public operations.– Must be stereotyped using the <<interface>>
keyword.– Must not have an attribute compartment.– Must not have associations.– Must have an operation compartment
containing the interface’s operations.
interface• The text editor uses a
platform-independent interface, window.
• The window is an abstract class, defining the functionality required of the window, but not providing it.
• The specialised classes are concrete implementation classes. These provide the functionality for window
• Java uses the word ‘implements’ to show this.
•May be used by other classes via a dependency stereotyped using the <<uses>> keyword.
Text editor Window
tofront()toback()
WindowsWindow
toFront()toBack()
X11Window
toFront()toBack()
MacWindow
toFront()toBack()
Another depiction…Text editor
Window
tofront()...toback()...
WindowsWindow
toFront()toBack()
X11Window
toFront()toBack()
MacWindow
toFront()toBack()
• May have generalisation relationships with other interfaces.
• May be supported by other classes via a ‘realises’ generalisation relationship from the supporting class to the interface class.– The supporting class must offer all the
operations defined in the interface class, and may offer new operations.
Templates
Templates / Parameterised classes
• These define a family of classes having a common form. • The differences between classes in the family are
represented by parameters, allowing a single template to instantiate many classes.
• Specific classes within this family are defined by specifying actual values that are bound to formal parameters.
• In the template, the parameters are unbound or unspecified.
• Also known as a parameterised class.
Templates / Parameterised class
• We want a class to list students and we want a class to list games.
• This could be done using two separate classes called StudentList and GameList, but they would have a lot in common.– Add element to the list.– Delete element from the list
• However, define List (T), which, given a class C to substitute for the formal parameter T, describes the class of lists of C objects.– an object of class List <Student> represents a list of students,– whereas an object of class List <Game> represents a list of
games.
Example
• A template class is shown as a class with a small dashed rectangle in the top right hand corner, which holds the formal parameters.
T
List
insert()remove()
Dependency
• Is denoted by a dashed arrow with the arrowhead pointing at the independent element.
• Relates elements of a model.• Don’t require instances to associate; they
exist among the model elements.• Have elements that exist at the same level
of abstraction or at the same level of detail.
• May be stereotyped using the <<refinement>> keyword to depict different semantic levels of abstraction. The refinement may be described in a note attached to the dependency.
• May serve as a container for a group of dependencies from parts of a client element to parts of a supplier element.
Dependency
• An association relationship is a dependency relationship when the object requesting (client object) the service of another object (server object) does not have intrinsic knowledge of the location of the server object - it must be told where the object is located.– Typically,
• either the server object is passed as a parameter to one of the methods of the client class
• or the server class is declared locally within a method of the client class.
Further exampleInputStream
<<Interface>>
DataInput<<Interface>>
OrderReader
DataInputStream
• The InputStream and the DataInput are abstract interface objects.
• The link between OrderReader and DataInput is a dependency.
• It shows that OrderReader uses the DataInput interface for some purpose.
• The link between DataInputStream and DataInput is a refinement. This indicates a greater level of detail.
Generalisation
Dependency
Refinement
Generating Code
From your ROSE model
Set up your path
• Create a directory for this work, such as U:\ROSE\StudentCode
• Edit the model properties (Tools>Model Properties>Edit)
• Click the Notation tab and choose Java as the default language.
• Set up the class path (Tools>Java>Project Specification
• Click the ‘new folder’ icon.
• Click the three dots.• Browse to find the
correct directory.
• Click OK• When the correct
directory is shown, click Apply.
For each class to be generated…
• Package classes– E.g. place all classes into a single package.
• Later, we will discuss strategies for packaging.
– To do this, add a package to the logical view and drag all the classes you need into it.
– Select each class and click Tools>Java>Generate Code
– Click Assign to assign your class to the chosen class path.
– You may get generation errors.
Typical errors
• Errors occur due to incompatibility between your model and the target language.
• E.g.– 10:44:57| WARNING: Class Logical View::OM_claim::Accident - the name
of attribute Accident date/time is not a valid Java identifier.10:44:57| ERROR: Class Logical View::OM_claim::Accident - a name which is a valid Java identifier cannot be constructed for attribute Accident date/time10:45:16| Starting Code Generation10:45:16| WARNING: Class Logical View::OM_claim::Accident - the name of attribute Accident date/time is not a valid Java identifier.10:45:16| ERROR: Class Logical View::OM_claim::Accident - a name which is a valid Java identifier cannot be constructed for attribute Accident date/time
• Note, these are errors due to an incompatibility between the given names and the Java language.
– i.e. you cannot call a field “Accident date / time”.
Error handling• Return to the class diagram and
fix the problems. • Generate again. This dialogue is
displayed:Insert a new classpath as shown on the next slide
• Returning to the Classpaths dialogue, click on the component and click ‘Assign’.
• The component then disappears from the RHS of the screen.
• When the code generation is complete, hopefully you will get ‘Code generation completed successfully’
• The following code has been generated into the folder: <folder name>
Data model generation
Using SQL Server
Converting classes to tables
• Classify the classes, using a 3-tier system– Tick the ‘Three-tier diagram’ box in the tools - options
menu in Rational Rose.
• Move all persistent classes into a single package.
• For each persistent business class:– Open the standard specification– Select the ‘detail’ tab– Turn on the ‘persistent’ radio button.
Using the Data Modeler
• Using the component view– Set up a database
• Right click on component view, choose data modeler, new, database.
– Open the specification for the database and choose the target database depending on the implementation route (e.g. SQL Server 2000)
• In the logical view– Set up a new schema
• Right click on logical view, choose data modeler, new, schema.
• Open the schema specification.• Associate it with the database you have created.
• Right click on the package in the Logical view
• Choose data modeler• Choose ‘Transform to
data model’• Fill in destination
schema and target database.
Result
• This creates a set of tables in the database.
• You can view them by setting up a new data model diagram.– Right click on schema– Choose data modeler– Choose new– Choose data model diagram
T_AssessorUsername : SMALLINTPassword : SMALLINTT_Assessor_ID : INT
<<PK>> PK_T_Assessor1()
T_AccidentAccident date/time : SMALLINTAccident location : SMALLINTAccident description : SMALLINTBus registration : SMALLINTT_Accident_ID : INT
<<PK>> PK_T_Accident0()
T_ClaimantClaimant name : SMALLINTClaimant address : SMALLINTDateOfBirth : SMALLINTT_Claimant_ID : INT
<<PK>> PK_T_Claimant3()
T_ExpertExpert name : SMALLINTExpertise : SMALLINTContact details : SMALLINTT_Expert_ID : INTT_Claim_ID : INT
<<PK>> PK_T_Expert4()<<FK>> FK_T_Expert2()<<Index>> TC_T_Expert5()
T_Expert ReportReport date : SMALLINTReport content : SMALLINTDate requested : SMALLINTT_Expert Report_ID : INT
<<PK>> PK_T_Expert Report5()
T_PaymentPayee : SMALLINTPayment amount : SMALLINTPayment status : SMALLINTPayment reason : SMALLINTAuthoriser : SMALLINTIssuer : SMALLINTT_Payment_ID : INTT_Claim_ID : INT
<<PK>> PK_T_Payment6()<<FK>> FK_T_Payment1()<<Index>> TC_T_Payment3()
T_Claimclaim reported date : SMALLINTclaim state : SMALLINTclaim type : SMALLINTT_Claim_ID : INTT_Accident_ID : INTT_Claimant_ID : INT
<<PK>> PK_T_Claim2()<<FK>> FK_T_Claim3()<<FK>> FK_T_Claim0()<<Index>> TC_T_Claim7()<<Index>> TC_T_Claim1()
1
0..*
1
0..*<<Non-Identifying>>
1
1..*
1
1..*
<<Non-Identifying>>
0..1
0..*
0..1
0..*
<<Non-Identifying>>
1
0..*
1
0..*
<<Non-Identifying>>
Generating SQL
• Right click on the database
• Choose Data modeler
• Forward Engineer…