Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generation and Implementation. More on classes Types Implementation classes Interfaces Templates Associations –Dependencies –Compositions.

Similar presentations


Presentation on theme: "Generation and Implementation. More on classes Types Implementation classes Interfaces Templates Associations –Dependencies –Compositions."— Presentation transcript:

1 Generation and Implementation

2 More on classes Types Implementation classes Interfaces Templates Associations –Dependencies –Compositions

3 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 > keyword. –Are implemented by implementation classes. –May have generalisation relationships to other types.

4 ‘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.

5 Unit Type value classes LengthAreaCubic volume Liquid volume WeightTemp- erature Centi- metres Square feet Cubic feetGallonsGramsDegrees Celcius KilometresSquare kilometres Cubic yards LitresKilogramsDegrees Fahrenheit FeetSquare Metres Cubic metres QuartsOuncesDegrees Kelvin InchesSquare miles Cubic metres Pounds Metres Miles

6 Implementation classes –are denoted as stereotyped class rectangles. –Must be stereotyped using the > 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.

7 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.

8 Interfaces

9 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.

10 interfaces Are equivalent to abstract classes with no attributes and no methods and only abstract public operations. –Must be stereotyped using the > keyword. –Must not have an attribute compartment. –Must not have associations. –Must have an operation compartment containing the interface’s operations.

11 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 > keyword.

12 Another depiction…

13 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.

14 Templates

15 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.

16 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 represents a list of students, –whereas an object of class List represents a list of games.

17 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.

18 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.

19 May be stereotyped using the > 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.

20 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.

21 Further example 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

22 Generating Code From your ROSE model

23 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.

24 Set up the class path (Tools>Java>Project Specification Click the ‘new folder’ icon. Click the three dots. Browse to find the correct directory.

25 Click OK When the correct directory is shown, click Apply.

26 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.

27 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/time 10:45:16| Starting Code Generation 10: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”.

28 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:

29 Data model generation Using SQL Server

30 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.

31 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.

32 Right click on the package in the Logical view Choose data modeler Choose ‘Transform to data model’ Fill in destination schema and target database.

33 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

34

35

36

37 Generating SQL Right click on the database Choose Data modeler Forward Engineer…

38


Download ppt "Generation and Implementation. More on classes Types Implementation classes Interfaces Templates Associations –Dependencies –Compositions."

Similar presentations


Ads by Google