Software Modelling Lecture Notes PDF 2024-2025
Document Details

Uploaded by WinningSanJose1484
University of Birmingham
2024
Tags
Summary
These lecture notes from the 2024-2025 academic year cover software modelling, including UML diagrams, use case scenarios, and activity diagrams. These notes discuss several features such as the library management system, functional requirements, and non-functional requirements. The content also delves into the application of noun/verb analysis and CRC cards for class diagram modelling.
Full Transcript
Week 4: Software Modelling [Part 2] Building Usable Software 2024-2025 UML (Recap) Use Case Diagram (Recap) Visually represent the interactions between actors (users or external systems) and a system. Used to define, understand, and communicate the functional r...
Week 4: Software Modelling [Part 2] Building Usable Software 2024-2025 UML (Recap) Use Case Diagram (Recap) Visually represent the interactions between actors (users or external systems) and a system. Used to define, understand, and communicate the functional requirements of a system. Relationships Use to show an option, alternating on normal behaviour, declaring the extension points in the base use case. Use to show uses, complementary functionalities, and logical dependencies, or avoid repetition when you are repeating yourself in two or more separate use cases. Use to describe a variation on normal behaviour, or inheritance relations. Activity Diagram (Recap) Used to model (work)flows. Show dependencies and coordination between activities within the system. Library Management System Members can register, update their information, search for books, and reserve books if available. Books in the system have details like title, author, ISBN, and genre. The system also allows checking the availability of books and notifying members about successful reservations. Features Library members can register and update their personal information. Books have unique attributes (e.g., title, author, ISBN, genre). The system allows checking the availability of books. Members can reserve available books. Notifications are sent for successful reservations. Functional Requirements FR (ID) FR Description User Management FR1 Library members can register and create accounts. FR2 Members should be able to update their contact information. Book Management FR3 The system must store book details (title, author, ISBN, genre). FR4 Members can search for books in the catalog. Book Reservation FR5 The system must allow members to reserve a book if it is available. FR6 Notifications must be displayed for successful reservations. Non-Functional Requirements NFR (ID) NFR Description Performance NFR1 The system must support at least 100 concurrent users without significant performance degradation. NFR2 Search queries should return results within 2 seconds. Scalability NFR3 The system must support future integration with eBook catalogs. Security NFR4 Member account data must be stored securely using encryption. Usability NFR5 The system must provide an intuitive and user-friendly interface. Use Case Diagram Register member Update information Check Library member availability Reserve Book Use case scenario Use case name: Reserve Book Actor: Library Member Precondition: The member must be logged into the system. Main Flow: 1. The member searches for a book in the catalog. 2. The system checks if the book is available. If available, the member reserves the book. If not available, the system notifies the member. 3. The system confirms the reservation and updates the book's availability status. Postcondition: The book is successfully reserved if it was available. Activity Diagram UML 2.X Class Diagram Use cases represent an external view of the system’s behaviour. Classes represent the inner structure of the system. No correlation between use cases and classes. Describes the structure of a system by modelling its classes, attributes, operations (or methods), and the relationships among objects. Consist of a set of classes and relationships between classes. When are Class Diagrams used? Class diagrams are used at different levels of abstraction with different levels of detail. Early design phase: identifying classes and their relations in the problem domain (high- level, no implementation details). Implementation phase: high level of detail (attributes, visibility, …), all classes relevant to implementing the system. Class Diagram: Elements Class Objects Classes is a template or blueprint for creating objects that Animal Dog share common structure and behaviour. Cat A class consists of: Turtle Attributes (Fields): Characteristics or properties of the class. Operations (Methods): Behaviours or functions of a class. Nouns/Start with capital Name Classname Animal Attributes and Operations Attributes Operations Represent the structure of a class. Represent the behaviour of a class. How to find them? How to find them? Examining class definitions Examining interaction between Looking at the requirements entities of the system. Applying domain knowledge Classname Animal attributeName: datatype id: int Attributes name: String (State) methodName(parameterNam _init_(id:int, name: String) Operations e:parameterType): returnType make_sound(sound: String): void eat(): void Class Visibility Animal + id: int + : Public – Visible too all classes. - name: String - : Private – Visible only within the class. + _init_(id:int, name: String) # : Protected – Visible to subclasses. + make_sound(sound: String): void Visibility notation - eat(): void Access Right Public (+) Private (-) Protected (#) Members of the same class. Yes Yes Yes Members of derived class. Yes No Yes Members of any other class. Yes No No Example Animal + id: int - name: String + _init_(id:int, name: String) + make_sound(sound: String): void - eat(): void Multiple instances/objects of the same class can be created by calling the same constructor/_init_function multiple times. Relationships X conatains a Y Any type of relationship or connection between classes. X is a Y A child class inherits functionality from the parent class. Two classes are associated, but not as close as in direct association. The subobject exists only as long as the contained class exists. Dependency X uses Y Relationships: Example Requirements Relationship A member is associated with multiple books. Association The reservation system depends on book availability. Dependency A Library contains Books, but books can exist independently. Aggregation The system supports different types of members, e.g., Students, Professors, and Guests. Generalization A reservation is linked to both a book and a member. Association A member receives notifications. Association A reservation contains a due date, meaning if the reservation is deleted, the due date is also removed. Composition Association Bi-directional relationship between two classes. Instances of one class connected to instances of another class. Describe the nature of the relationship A solid line connecting the classes, with optional arrow indicating the direction of the relationship. Navigability A→B Class A has access to Class B through: Direction denotes whether 1. Methods in class A that access objects can be accessed attributes in class B or through this association. 2. Attributes in class A that hold instances of class B. AB Class B has access to Class A through: 1. Methods in class B that access attributes in class A or 2. Attributes in class B that hold instances of class A. A -- B Class A and B have acess to attributes and/or instances within each other. Multiplicity 0..1 → Zero to One How many objects of each class take part in the relationships? n → Specific number 0..* → Zero to Many 1..* → One to Many Example: Association → A member is associated with multiple books. → A reservation is linked to both a book and a 1 member. 1 → A member receives notifications. 1 1 1 1 1 0..* Inheritance (or Generalization) Represents an "is-a" relationship. The child classes inherit the attributes and operations of the parent class. Generalization simplifies the model by eliminating redundancy. SubClass1 and SubClass2 are specializations of Super Class. Parent class A solid line with a hollow arrowhead that points from the child to the parent class. Child class Example: Inheritance → The system supports different types of members, e.g., Students, Professors, and Guests. Aggregation Class A is a part of Class B, but Class B can exist independently. Aggregation: Denotes a “consist of” hierarchy. Component can be part of multiple aggregates. Component can be created and destroyed independently of the aggregate. Answer: Aggregation represents a "whole-part" relationship where the parts - Course can exist independently of the whole - Curriculum. Analysis: A curriculum consists of many courses, but the course can exist independently of the curriculum. Parent Child If the curriculum is deleted, the course can still be class class part of other curricula. Composition Strong Aggregation A component can only be part of a single aggregate. Exists only together with the aggregate. Class 2 cannot stand without Class 1. Example: Aggregation and Composition Example: Aggregation and Composition Answer: Aggregation represents a "whole-part" relationship where the parts - Instructor can exist independently of the whole - Course. Analysis: A course can be taught by one or more instructors. An instructor can teach multiple courses. A course can still exist even if an instructor leaves the course or switch to teach other courses. Answer: Composition represents a strong ownership. Analysis: The part – engine can’t exist independendly of the whole- car. If the whole – car is deleted, the part – engine is also deleted. Example: Aggregation and Composition → A reservation contains a due date, meaning if → A Library contains Books, but the reservation is deleted, the due date is also books can exist independently. removed. Aggregation is used when the part (Book) can exist independently of the whole (Library). - Books can be transferred to a different library. ` - If library closes, the books will remain in the system. - Books can belong to multiple libraries. Composition represents a strong ownership. - The part – due date can’t exist independendly of the whole- reservation - If the whole – reservation is deleted, the part – due date is also deleted. Dependency uses Exists between two classes if the changes to the definition of one may Class1 depends on Class2 but doesn’t own it. cause changes to the other (but not A dashed line with an open arrow pointing the other way around). from the dependent at the tail to the provider at the arrowhead. → Notifications depend on reservations. Depends on reservation Class Diagram Modelling Steps How to identify Classes and Attributes? 1. Data-Driven Analysis (i.e. noun/verb analysis) This can be done from a general problem description, or better, from a use case or scenario. Map parts of speech to object model components. * nouns usually map to classes, objects, or attributes * verbs usually map to operations or associations. 2. Responsibility-Driven Design (CRC cards) Identify all the responsibilities in the system Divide into classes before considering the classes’ data Noun/Verb Analsis Steps: 1. Perform noun-verb analysis of your requirements document; 2. Underline all the noun and noun phrases; 3. Create a list of candidate classes (in examining the discard criteria, you may also identify some candidate attributes); 4. Identify all the verbs (candidate operations) in the use case diagram; 5. Assign them to classes where they should be implemented. Responsibility-Driven Design A CRC card is an index card with three parts: Class -- name goes at the top of the card Responsibilities -- as a list on the left side of the card Collaborators -- as a list on the right side of the card Class Name (One card per class) Responsibility Collaborator Something that the class knows Another class that the current class has to work with to (keeps track of) or does complete its responsibilities These should be the high-level Could be a class that has information we need responsibilities. Not trying to list out Could be a class that helps perform a task all member functions here. Typically, we list a class as a collaborator if the current class needs to call upon it to help complete our own responsibilities. Responsibility-Driven Design Process Basic: Simulate the execution of use case scenarios/user stories Steps: 1. Brainstorm classes/objects/components 2. Assign classes/objects/components to persons (groups up to 6) 3. Execute the scenarios one by one a) Add new classes/objects/components as needed b) Add new responsibilities c) delegate to other classes/persons (collaborators) Noun/Verb Analysis vs. CRC card Noun/Verb analysis: Identify all the data in the system and divide it into classes, before considering the responsibilities. CRC card: Identify all the responsibilities in the system and divide them into classes before considering the classes’ data. Step 1: Identify Classes and Attributes 1. Underline all the nouns in the functional requirements table. 2. Categorize them as classes and attributes (properties, fields). FR (ID) FR Description User Management FR1 Library members can register and create accounts. FR2 Members should be able to update their contact information. Book Management FR3 The system must store book details (title, author, ISBN, genre). FR4 Members can search for books in the catalog. Book Reservation FR5 The system must allow members to reserve a book if it is available. FR6 Notifications must be displayed for successful reservations. Step 2: Identify Methods Register member 1. Identify all the verbs (functions, operations) in the use case diagram. Update information 2. Assign them to classes where they should be implemented, no Check where they should be called. Library member availability Reserve Book Step 3: Draw Class Diagram 1. Create a class box for each class identified and its attributes. 2. Add methods with their parameters and return types. 3. Add attributes that are needed to fulfil the methods. 4. Add visibility notation (+, -, #). 1 5. Draw relationships between classes and multiplicity reserves and role names if needed. 0..* 6. Review and refine as needed. Code Practice Provide a Python code for the following classes Member Class: Attributes: MemberID, Name, ContactInfo Operations: register(), updateInfo() Book Class: Attributes: ISBN, Title, Author, Genre Operations: checkAvailability(), reserve() To remember… What can a class diagram show? Division of Responsibility: Operations that objects are responsible for providing. Subclassing: Inheritance, generalization. Navigability / Visibility: When objects need to know about other objects to call their operations. Aggregation / Composition: When objects are part of other objects. Dependencies: When changing the design of a class will affect other classes. Interfaces: Used to reduce coupling between objects. To remember… Class diagram help us Understand the problem Select meaningful class names (mapping real-world model into entities) Structure of the system (entities and its characteristics) (WHAT) – no how Start with a simple diagram and refine it.