Download presentation
Presentation is loading. Please wait.
Published byBjørg Gundersen Modified over 5 years ago
1
Object-Oriented Software Development: Class Diagrams and Its Implementation
Chih-Ping Chu Dept. of Computer Science & Information Engineering National Cheng Kung University
2
Outline Features of object-oriented software
Developing OO systems based on models UML diagrams Essentials of class diagrams Implementing class diagrams
3
Models are used for: - leading software engineers to have
insights about the system - providing abstraction - helping create designs - permitting analysis and review of those designs. (check design) - being the core documentation describing the system.
4
UML diagrams Class diagrams - describe classes and their relationships
Interaction diagrams - show the behaviour of systems in terms of how objects interact with each other State diagrams and activity diagrams - show how systems behave internally Component and deployment diagrams - show how the various components of systems are arranged logically and physically
5
Class diagrams
6
Interaction diagrams
7
State diagrams and activity diagrams
9
Component and deployment diagrams
10
Essentials of UML Class Diagrams
The main symbols shown on class diagrams are: Classes - represent the types of data themselves Associations - represent linkages between instances of classes Attributes - are simple data found in classes and their instances Operations - represent the functions performed by the classes and their instances Generalizations - group classes into inheritance hierarchies
12
Implementing Class Diagrams in Java
- Attributes are implemented as instance variables - Generalizations are implemented using extends - Interfaces are implemented using implements - Associations are normally implemented using instance variables - Divide each two-way association into two one- way associations so each associated class has an instance variable.
13
- For a one-way association where the multiplicity at the other end is ‘one’ or ‘optional’
- declare a variable of that class (a reference) - For a one-way association where the multiplicity at the other end is ‘many’: - use a collection class implementing List, such as Vector
14
An example: A Flight Booking System
16
An example: A Flight Booking System
17
Creating an association class, given two existing objects
class Passenger { private ArrayList<Booking> bookings = new ArrayList<Booking>(0); private String name; public void makeBooking(SpecificFlight flight, int seatNumber) new Booking(this, flight, seatNumber); } void addLinkToBooking(Booking bookOne) // link booking bookings.add(bookOne);
18
class Booking //association class
{ Passenger passenger; // due to one to one relation SpecificFlight flight; //due to one to one relation int seatNumber; Booking(Passenger passenger, SpecificFlight flight, int seatNumber) this.passenger = passenger; this.passenger.addLinkToBooking(this); this.flight = flight; this.flight.addLinkToBooking(this); this.seatNumber = seatNumber; }
19
void addLinkToBooking(Booking bookOne) booking.add(bookOne); }
class SpecificFlight { private ArrayList<Booking> booking = new ArrayList<Booking>(0); private String name; void addLinkToBooking(Booking bookOne) booking.add(bookOne); }
21
Making a bi-directional link between two existing objects;
class SpecificFlight { private Calendar date; private RegularFlight regularFlight; ... // Constructor that should only be called from // addSpecificFlight SpecificFlight( Calendar aDate, RegularFlight aRegularFlight) date = aDate; regularFlight = aRegularFlight; }
22
class RegularFlight { private List specificFlights; ... // Method that has primary responsibility public void addSpecificFlight(Calendar aDate) SpecificFlight newSpecificFlight; newSpecificFlight = new SpecificFlight(aDate, this); specificFlights.add(newSpecificFlight); }
24
Creating an object and linking it to an existing object
class SpecificFlight { private FlightLog log; private RegularFlight regularFlight; ... public void createFlightLog () log = new FlightLog(); }
25
class FlightLog { ... FlightLog () // constructor }
26
Searching for an associated instance
import java.util.Iterator; class SpecificFlight { private ArrayList<EmployeeRole> employees = new ArrayList<EmployeeRole>(0); private EmployeeRole anEmployee; ... public EmployeeRole findCrewMember (String name) for (Iterator<EmployeeRole> iterator = employees.iterator(); iterator.hasNext();) anEmployee = (EmployeeRole) iterator.next(); if anEmployee,getname() == name return anEmployee; }
27
class EmployeeRole { private String name; ... public String getName() return name; } () }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.