Download presentation
Presentation is loading. Please wait.
Published byDavid Gardner Modified over 8 years ago
1
Prepared by Mrs.Atiya Masood Constructing an Initial Structural Model I CHAPTER 33
2
Prepared by Mrs.Atiya Masood New concepts this chapter introduces a number of new ideas connected with object-oriented analysis, including generalisation relationships, recursive associations, derived associations and invariants. In addition, you are introduced to a range of guidelines and techniques that can be used to identify classes, attributes and associations from a negotiated statement of requirements.
3
Prepared by Mrs.Atiya Masood Introduction In this chapter, we shall look at how we can analyse such an NSR in order to begin the process of determining the appropriate classes and associations, responsibilities and collaborations.
4
Prepared by Mrs.Atiya Masood Introduction Application area: the real-world context within which the system is required to operate. Problem domain: the collection of real-world entities within the application area that exhibit those behaviors that the required system has to model. User communication: the means by which communication between the problem domain and the rest of the application area takes place. Domain model: the part of the system that models the problem domain. Structural model: a representation of the problem domain in terms of classes and the relationships between them. Initial structural model: represents the structure of the required system in terms of classes and their relationships without considering how responsibilities for the details of the required behaviours should be distributed among the classes.
5
Prepared by Mrs.Atiya Masood Identifying classes and attributes Classes:- A class encapsulates the behaviour of a set of objects of the same kind. Attributes:- are properties of objects. An object’s behaviour may depend upon the values of its attributes. An association exists between two (not necessarily distinct) classes when there can be links between (some of) their respective objects. When looking for classes, is to identify the things whose behaviour – either behaviour that is about recording something or behaviour that is about doing something – is significant for the application area.
6
Prepared by Mrs.Atiya Masood Identifying classes and attributes To identifying classes is to identify nouns or noun phrases in the NSR.
7
Prepared by Mrs.Atiya Masood Identifying classes and attributes Grouping together nouns and noun phrases that are synonyms, library copy (video copies, copies, video copy) film (films, number of films) system title (film's title) unique identifying number member (library member) unique membership number member's name the number of copies of that film that are currently available for loan the films that that member currently has copies of on loan. Note that a singular noun is used to represent each group of synonyms.
8
Prepared by Mrs.Atiya Masood Identifying classes and attributes Guidelines for rejection Is it an attribute? Does it correspond to a simple property of some other category of object in the application area? Are its possible values simple, possibly ‘pre-defined’, things like strings or numbers or addresses. Ex:-‘title’, which is an attribute of a film; ‘unique identifying number’, which is an attribute of a copy; ‘unique membership number’, which is an attribute of a member; ‘name’, which is another attribute of a member. Does it refer to a behaviour of the system? Does it name some process or identify some result of a process that the system has to carry out? the number of copies of that film that are currently available for loan;
9
Prepared by Mrs.Atiya Masood Identifying classes and attributes Is it outside the scope of the system? Is it a word or phrase that is used to help describe how the system works or what it consists of, but that does not actually refer to something that is inside the system? Ex: library itself does not need to be modelled: it has no behaviour that is relevant to the application area. A group of video libraries rather than a single ‘library’, then the category library would correspond to a class in the domain model, example, which library holds a particular copy. Does it refer to an aspect of the user interface? Does it describe something concerning the interaction of a user with the system, rather than something that is part of the system itself? ‘ The librarian enters the copy code by using a barcode reader.’ Both ‘librarian’ and ‘barcode reader’ may be rejected, since they refer to aspects of the user interface.
10
Prepared by Mrs.Atiya Masood Identifying classes and attributes Is it a word or phrase that is used in talking about the system that is to be developed rather than a reference to something in the application Ex: Words like ‘system’, ‘behaviour’ and ‘requirement’ fall into this category; they do not refer to entities in the application area. Does it refer to links between other objects in the system? In such a case, it is possible that it corresponds more appropriately to an association than to a class. Ex: Loan:- hasOnLoan It is important to note that these are guidelines and not strict rules. it is possible for something to fall into one of the above categories and still require to be represented by a class in the domain model.
11
Prepared by Mrs.Atiya Masood Identifying classes and attributes we end up with the following list of candidate classes: Copy, Film and Member. Kinds of classes (Adapted from Schlaer, S. and Mellor, S. (1988) Object- Oriented Systems Analysis:) Tangible objects By this we mean physical things in the world of the application area: aeroplanes, vehicles, reactors, and so on. Ex: Copy Roles By this we mean the role or roles that people play in the application area – employee, student, lecturer, driver, and so on. Ex: Member
12
Prepared by Mrs.Atiya Masood Kinds of classes Events:- By this we mean a circumstance, episode, interaction, happening or significant incident for which it seems likely that some sort of record will need to be kept in the application area – deliveries, registrations, bookings, enrolments, and so on. Organisational units:- By this we mean the organisational units to which people or things in the application area belong – departments, faculties, branches, and so on. Into which category would you place the class Film in the Video Library system???
13
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Hospital ward patient name of ward supervisor Administration department consultant doctor junior doctor grade of junior doctor doctor team team code name of doctor address of doctor
14
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Candidate classes for the system: Ward (tangible) Patient, Consultant Doctor, junior doctor, Doctor ( Role) Team (Organisational Unit) Note: Each class name is a single word starting with an uppercase letter. The class name should be singular; patients are represented by the instances of Patient rather than by the class itself. UML notation, classes are represented in a class diagram by a rectangle with the class name inside it,
15
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Attributes come under the heading of responsibilities. It is important to recognise that when listing attributes in a class description. Thing or property? As well as a name and an address, a doctor has a title; also, a record is kept of the institution where he or she qualified. Look the above statement of client. In this statement name is class or attributes??? If it is significant information in application area, where we must focus on it - Class If it is some basic information of other object attributes So name is attributes of doctor
16
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Generalisation relationships A relationship between classes that allows us to recognise the similarities and differences between two related classes. What is the relationship between Doctor and JuniorDoctor? JuniorDoctor is a kind of doctor as well as ConsultantDoctor Doctor generalises JuniorDoctor and ConsultantDoctor. generalisation relationship between the classes Doctor and JuniorDoctor and also between Doctor and ConsultantDoctor.
17
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Doctor Parent class JuniorDoctor and ConsultantDoctor Specialisation (or child class) Arrow indicates the more general class Child class inherit all attributes of Parent class
18
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced An instance of a child class should always be substitutable for an instance of its parent class. Anywhere an instance of Doctor is required we can use an instance of JuniorDoctor. ‘Any instance of Doctor is linked to exactly one instance of Team ’ we can replace Doctor by JuniorDoctor to get ‘any instance of JuniorDoctor is linked to exactly one instance of Team ’. A child class inherits all the attributes, associations and behaviour of its parent class.
19
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Abstract classes A class, each instance ‘of’ which is in fact an instance of one of its subclasses, is called an abstract class. No instance of abstract class Every object ‘of’ the abstract class is actually an instance of one of the concrete subclasses. Read this and tell me which class is abstract class and why? Each team is headed by a consultant doctor who is the only consultant doctor in the team; the rest of the team are all junior doctors, at least one of which must be at grade 1. Each doctor is in exactly one team.
20
Prepared by Mrs.Atiya Masood Associations An association between two (not necessarily distinct) classes is a set of links that have a common meaning. By a link we mean a connection between a pair of objects Hospital Admission and Treatment (HAT) system introduced these links are instances of an association called isCopyOf.
21
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced The name of an association should be a single ‘word’. Association names should start with a lower-case letter. The name we choose should give an indication of the meaning of the association. Arrow head Indicating the direction in which the name should be read Usually the direction in which the name should be applied is obvious,
22
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Identifying associations Such grammatical structures are often verbs, verb phrases or prepositional phrases. Read the NSR of HAT and identify Association between Ward,Team, Doctor, ConsultantDoctor, Paitent,JuniorDoctor. Incomplete Class Diagram
23
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced An important point to note is that, when there is a generalisation relationship, a child class (subclass) inherits the associations of the parent class (superclass). In the HAT system, for example, both JuniorDoctor and ConsultantDocto inherit the hasTreated and the consistsOf associations from Doctor. This follows from the fact that instances of a child class must be substitutable for instances of the parent class.
24
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Multiplicity:- tells us the range of possible values for the number of instances of one class linked by the association to other Class. Types of Multiplicity One-to-many association The word ‘one’ means a multiplicity of 1 or 0..1 The word ‘many’ is used to indicate a multiplicity involving numbers greater than 1 such as 0..*, 1..*, 0..2, 5..17, 4, and so on.
25
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced One-to-one associations:- A one-to-one association is one in which the instances of the classes at either end are never linked to more than one instance of the class at the other end. In other words, the multiplicities at each end are one. 1 1 Team ConsultantDoctor Many-to-many associations An instance of either class may be linked to more than one instance of the other class. Doctor {abstract} Patient isHeadedBy 0..* hasTreated 0..*
26
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Recursive associations An association to exist between a class and itself. Example: Some nurses supervise other nurses. A nurse is supervised by at most one other nurse.
27
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Inheritance:- By inheritance we mean the way in which a specialisation of a class inherits all the properties of the parent class. For simplicity we refer to the classes involved as subclasses and super classes. Doctor is an abstract class, it will not have any instances, should we retain it or not? it should be retained. why? The most important reason (at this stage) is that it models a significant category of objects in the problem domain. Doctor class defines the common behaviour and properties of its subclasses it ‘abstracts’ out the common associations (hasTreated, consistsOf ) and attributes (name, address) of the classes JuniorDoctor and ConsultantDocto
28
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced In addition, a subclass should normally satisfy at least one of the following: – It has additional attribute(s) not possessed by the superclass. – It has additional behaviour not possessed by the superclass. – It has additional association(s) not possessed by the superclass. If none of these held, it would be unlikely that the subclass would be needed at all; instances of the superclass
29
Prepared by Mrs.Atiya Masood We do not have a Treatment class to represent the treatment of a patient by a doctor. Why? Does the event have any attributes whose values need to be recorded? example, we might want to record the date of the treatment or what medication the treatment involved. If so then we should use a class. Does the event involve more than two other classes in the problem domain? For example, a treatment might always involve a nurse as well as the patient and the doctor. If that were the case a class would be more appropriate. There is no need to introduce a Treatment class. Hospital Admission and Treatment (HAT) system introduced
30
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Derived association A derived association is one whose instances can be derived using other association instances. The NSR states that: Each patient is under the care of a single team of doctors. The consultant who heads that team is responsible for the patient. Since p is linked via caresFor to an instance t of Team, the instance of ConsultantDoctor that is linked to p via isResponsibleFor is just the instance of ConsultantDoctor that is linked to t via isHeadedBy. isResponsibleFor can be derived from caresFor and isHeadedBy
31
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced Derivation of isResponsibleFor If p is an instance of Patient then p is linked via caresFor to exactly one instance t of Team. The instance of ConsultantDoctor linked to p via isResponsibleFor is the instance that is linked to t via isHeadedBy. In a class diagram we indicate that an association is a derived association by preceding its name with a /.
32
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced The associations isResponsibleFor, isHeadedBy and caresFor form a ‘loop’. Identify possible derived associations is to look for such loops in the class diagram. Many loops will not give rise to derived associations- loops simply indicate likely places to look for them. Why we do not simply remove the derived association isResponsibleFor ; it is, in a sense, redundant.
33
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced First is that isResponsibleFor models a relationship that is explicitly mentioned in the requirement. second is that we could argue that it is the caresFor association that is redundant, and not the isResponsibleFor association. This is because the caresFor association can be derived by using the isResponsibleFor and the isHeadedBy associations. Do exercise # 10 The associations hasTreated, consistsOf and caresFor also form a loop. Can we extract derived associations?
34
Prepared by Mrs.Atiya Masood Hospital Admission and Treatment (HAT) system introduced
35
Prepared by Mrs.Atiya Masood Invariant An invariant is a condition involving classes and associations that must hold if the NSR is to be satisfied. Invariant written in formal language. The invariant are required when there is a loop in the class diagram. Example: If an instance of Patient is linked to an instance of Doctor via hasTreated then that instance of Doctor must be linked via consistsOf to an instance of Team that is linked via caresFor to the original instance of Patient..
36
Prepared by Mrs.Atiya Masood Invariant Some invariant are absent in class diagram A patient may be treated by any number of doctors but they all must be in the team that cares for the patient. This is an important invariant, and it is not evident from the class diagram. We can state it formally as follows. If p is an instance of Patient that is linked to an instance d of Doctor via hasTreated then d must be linked via consistsOf to the instance of Team that is linked via caresFor to p.
37
Prepared by Mrs.Atiya Masood Invariant Another common form of invariant is one that places restrictions on the values of the attributes of objects that can participate in certain associations Example: the rest of the team are all junior doctors, at least one of which must be at grade 1. If t is an instance of Team then there must be at least one instance jd of JuniorDoctor such that t is linked via consistsOf to jd and jd has grade 1.
38
Prepared by Mrs.Atiya Masood Invariant Invariants can concern the uniqueness of certain attributes. Example: no two patients on the same ward can have the same name. Similarly, no two wards can have the same name. We can express these as follows. If p1 and p2 are instances of Patient that are linked via hasOn to the same instance of Ward then the name of p1 is not the same as the name of p2. If w1 and w2 are instances of Ward then the name of w1 is not the same as the name of w2.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.