UML CLASS DIAGRAMS Basics of UML Class Diagrams • What is a UML class diagram? Imagine you were given the task of drawing a family tree. The steps you would take would be: – Identify the main members of the family – Identify how they are related to each other – Find the characteristics of each family member – Determine relations among family members – Decide the inheritance of personal traits and characters Basics of UML Class Diagrams • A UML class diagram is similar to a family tree. • A class diagram consists of a group of classes and interfaces reflecting important entities of the business domain of the system being modeled, and the relationships between these classes and interfaces. • The classes and interfaces in the diagram represent the members of a family tree and the relationships between the classes are analogous to relationships between members in a family tree. • Interestingly, classes in a class diagram are interconnected in a hierarchical fashion, like a set of parent classes (the grand patriarch or matriarch of the family, as the case may be) and related child classes under the parent classes. Basics of UML Class Diagrams • Similarly, a software application is comprised of classes and a diagram depicting the relationship between each of these classes would be the class diagram. • By definition, a class diagram is a diagram showing a collection of classes and interfaces, along with the collaborations and relationships among classes and interfaces • A class diagram is a pictorial representation of the detailed system design • Now you now know what a class diagram is. But, how does a class diagram relate to the use case diagrams that that we learned before? Basics of UML Class Diagrams • When you designed the use cases, you must have realized that the use cases talk about "what are the requirements" of a system. • The aim of designing classes is to convert this "what" to a "how" for each requirement • Each use case is further analyzed and broken up into atomic components that form the basis for the classes that need to be designed Elements of a Class Diagram • A class diagram is composed primarily of the following elements that represent the system's business entities: – Class: A class represents an entity of a given system that provides an encapsulated implementation of certain functionality of a given entity. These are exposed by the class to other classes as methods – Apart from business functionality, a class also has properties that reflect unique features of a class. The properties of a class are called attributes. – As an example, take a class named Student. • The Student class encapsulates student information such as student id #, student name, and so forth. Student id, student name, and so on are the attributes of the Student class. The Student class also exposes functionality to other classes by using methods such as getStudentName(), getStudentId(), Elements of a Class Diagram…. • A class is represented by a rectangle. The following diagram shows a typical class in a class diagram: Elements of a Class Diagram…. – Interface: An interface is a variation of a class. As we saw from the previous point, – a class provides an encapsulated implementation of certain business functionality of a system. An interface on the other hand provides only a definition of business functionality of a system. A separate class implements the actual business functionality. – An interface shares the same features as a class; in other words, it contains attributes and methods. The only difference is that that the methods are only declared in the interface and will be implemented by the class implementing the interface. Elements of a Class Diagram…. – Package: provides the ability to group together classes and/or interfaces that are either similar in nature or related. – Grouping these design elements in a package element provides for better readability of class diagrams, especially complex class diagrams. Figure —a package Relationship Between Classes • The following table shows the kinds of relationships between classes, their notation, and what they mean Relationship Between Classes…. The UML Class Diagram in Action Case study—Courseware Management System • In the use case lecture, we identified the primary actors and use cases in the use case model of the case study. • Let us recap the analysis that was performed when the use case model was designed. • The following terms and entities specific to the system were identified from the problem statement: – Courses and Topics that make up a course – Tutors who teach courses – Course administrators who mange the assignment of the courses to tutors – Calendar or Course Schedule is generated as a result of the Students who refer to the Course schedule or Calendar to decide which courses for which they wish to sign up The UML Class Diagram in Action…. Case study—Courseware Management System • The potential actors of the system were: – Tutors – Course administrators – Students • And the use cases of the system were: – – – – – – – View courses Manage topics for a course Manage course information View course calendar View tutors Manage tutor information Assign courses to tutors The UML Class Diagram in Action…. Identifying classes of the Courseware Management System • Identify the "active" entities in the system – So, our first list of classes in the system appears to be: – Course administrators – Tutors – Students • Identify business domain ("passive") entities in the system – These entities reflect the business domain and hence are potential classes for our system. – Courses – Topics that make up a course – Course calendar generated The UML Class Diagram in Action…. Identifying classes of the Courseware Management System • So, the list the list of classes and interfaces that we have identified in the Courseware Management System. – – – – – – Course Administrator Tutor Student Course Topic Course Calendar The UML Class Diagram in Action…. Identifying methods of the Courseware Management System • The classes that we have identified for the Courseware Management System also provide business functionality related to the application • Example the courseadministrator class have the following functionality (methods): The UML Class Diagram in Action…. Identifying methods of the Courseware Management System • Other classes have methods as shown in the figure below? The UML Class Diagram in Action…. Identifying relationship and drawing the class diagram Other examples of Class Diagrams • Seminar Management System QUESTIONS