1 / 12

Class Diagrams

Class Diagrams. In UML class diagrams are used to represent classes and relationships between classes. Each class is represented as a box divided into three parts specifying the: Name of the class Data elements of the class Methods of the class. The student class. Class name.

minna
Télécharger la présentation

Class Diagrams

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class Diagrams • In UML class diagrams are used to represent classes and relationships between classes. • Each class is represented as a box divided into three parts specifying the: • Name of the class • Data elements of the class • Methods of the class

  2. The student class Class name Data elements Methods

  3. Associations • Associations represent interactions between objects • Examples: • A student registers for a course. • A customer places an order. • An employee has a particular medical scheme.

  4. Example • A customer buys a product

  5. Another Example • A student registers for a programme

  6. Example 1 • Define the classes that you would use for the following system. Specify the data elements and methods of each class. You need to develop a system that keeps track of customers accounts. Information stored for each customer is the customer name, address and phone number. A customer may place one or more orders. Each order has an order number, date and amount and a description of the product to be shipped. Each product has a unique product number, description and price.

  7. Example 2 • Define the classes that you would use for the following system. Specify the data elements and methods of each class. You are required to develop a GUI for an existing application. The main component of the GUI is a form. The form has a width, height, boarder style and background color. The user must be able to display or close a form. The user must also be able to minimize and maximize the form. The form contains labels and buttons. Labels have a size, shape, color and text. The programmer must be able to set the text, get the text, hide the label or display the label. Each button has a size, shape, colour, location and caption. The user should be able to click the button. A programmer must be able to hide, display, enable or disable the button.

  8. Superclasses and Subclasses • Some classes can be defined as subclasses of other classes which we call superclasses. • Examples • Superclass: Person Subclass: Customer • Superclass: Birds Subclass: Penguins • A subclass inherits all the data elements and methods of its superclass. • In addition to these a subclass usually has data elements and methods of its own. • The relationship between subclasses and superclasses is referred to as inheritance. • A subclass is said to extend the superclass.

  9. Inheritance Examples • Superclass: Student • Subclasses: GraduateStudent, UndergraduateStudent • Superclass: Shape • Subclasses: Circle, Triangle, Rectangle • Superclass Loan • Subclasses: CarLoan, HomeImprovementLoan, MortgageLoan

  10. Example Information stored for each student in the database includes the student’s name, student number, address, matric points and the degree the student is registered for. The student’s majors and year of study is stored for each undergraduate student. For each postgraduate student the student’s subject area and supervisor are stored.

  11. UML Class Diagram

  12. Exercise Draw a class diagram for the following system: Suppose that you are required to implement a system that stores information whenever a customer makes a purchase. The information that must be stored includes the customer ID number, name, address, telephone number and amount due for the purchase. If a customer pays cash for the goods purchased, then he or she receives a discount for the particular purchase. Thus, in this case the amount_due is calculated to be the cost of the goods minus a percentage (discount_percent) of the cost. For example, if the cost of the goods purchased is R100 and the discount_percent is 0.10 then the amount_due is R90. If the customer purchases goods on credit the amount due is the cost of the goods plus a percentage (add_on_percent) of the cost. The monthly_instalment is this value divided by 12. For example, if the cost of the goods is R200 and the add_on_percent is 0.2 then the amount_due is 200+200*0.2= R 240 and the monthly_instalment is R20.

More Related