Modelling Classes-detailedsclass_student


发布时间:2017-03-23 来源:本站原创 作者:本站编辑   


DETAILED CLASS  MODELLING                       M.Ratcliffe

 

NAVIGATION

 

Identifies the direction of potential messages between instances of one class and instances of another where there is an association between the two of them.

 

In the UML, you can put an open arrowhead on the end of an association to

indicate that it is possible to reach one class from another following the direction of the

arrow.

 

 In doing so, you are restricting access to instances of the class at end of the

association where you placed the arrowhead

 

No arrows indicates navigation in both directions

 

 

 

 

 

 

 

 

An invoice line cannot send a message to the invoice

 

Navigability is mainly of use during implementation when you have to

decide how to write the code that represents an association.

 

 

 

 


QUALIFIED ASSOCIATIONS

 

Allows the use of association information to refine associations.

 

 

EXAMPLES

 

A Bank may be associated with zero or more accounts

 

 

However, given the combination of a bank and an account number, there is either zero or one associated account. So we can use accountNo as a qualifier:

 

 

 

 

This tells you something extra about the BankAccount association

 

A qualified association often replaces an association with a multiplicity of * with a multiplicity of either 1 or 0..1.

 

In the UML, a qualifier is considered to be an attribute of an association.

 

It tells you about the properties of the concept that relates the classes at the ends of the association.

 

In practice, qualifiers can be found in the attributes of one of the classes.

 

In cases where objects can be uniquely identified by combinations of two or more

attributes, all those attributes should move into the qualifier.

 

 


DERIVED ASSOCIATIONS/ATTIBUTES

 

By preceding a role name with a slash, you indicate that an association is derivable, i.e these associations do not require additional links between the classes to be implemented.

For example, a family object can implement code to derive the set of teenagers from the allChildren  association.

 

Similarly, we can have derived attributes.

 

 

 

 

 

 

 

DETAILED CLASS  MODELLING EXERCISE  1

 

1. In a multi-user operating system, users are allocated passwords. Draw a fragment of

a class model to represent this association. Bear in mind that you do not want to be

able to identify the corresponding user for a given password.

 

 

2. Build a class model associating companies, libraries and families with persons,

identifying persons by suitable qualified associations.

 

 

 

 

 

 

 


INTERFACES AND POLYMORPHISM

 

Interfaces are defined by listing operations

 

The interface simply identifies a set of operations by naming each one. It does not

provide any implementation.

 

The UML allows uses a variant of the class notation, with the stereotype <<interface>> to represent  interfaces.

 

A stereotype is a label that maybe added to a model element such as a class or an association to convey extra information.

 

To show that a class implements the interface, the UML uses the realization arrow  – a  dotted line with a closed arrowhead.

 

This is a weak form of inheritance as the interface specifies no implementation.

 

 

EXAMPLE

 

Systems relating to the sale of goods tend to be interested in those classes that have operations such as getPrice, getVATRate and getDiscountLevel.

 

An  interface called Sellable can be defined  that names all the operations that a class must have in order that it fits in with the sales subsystem. You might call an object Sellable if it had all these operations.

 

 

 

 

 

 

The way the price of a book and that of a car is calculated may be totally different.

 

Therefore the classes Car and Book would have different implementations of the

operation getPrice. All that matters to the user is that both classes do implement all the

operations listed in the interface.

 

The only time an object needs to be aware of a class is when the object creates an

instance of that class. Then it needs to mention the class of the new instance directly.

After that, the object communicates with the new instance through its interface.

 

A Bill can have a relationship to a number of Sellable instances and use them to compute financial figures such as a total price, without knowing which

classes support the interface. The Bill is totally independent of these classes. If in the

future the business starts selling clothes and meals, the same billing system will work,

providing all the new classes implement the Sellable interface.

 

 

 

.

 

 


DEPENDENCIES

 

 

A dependency can be shown between any two elements in the UML.

 

A dependency exits between the elements if a change in one affects the other.

 

Shown in the UML with the dependency arrow – dashed arrow.

 

 

 

 

 

Dependencies between classes are usually shown in their more specific forms : association, inheritance.

 

Dependencies are most commonly used between packages. Packages may contain any UML element. It is therefore useful to have the notion of dependency to specify that a package depends on an element in another package -  without having to be specific.