Top Banner
Topics Sub Classes, Super Classes Specialization and Generalization • Participation Constraints • UML Class Diagram
40

Uml

May 11, 2017

Download

Documents

Anthony Pringle
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Uml

Topics

•  Sub Classes, Super Classes•  Specialization and Generalization• Participation Constraints• UML Class Diagram

Page 2: Uml

Subclasses and Superclasses (1)

• An entity type may have additional meaningful subgroupings of its entities– Example: EMPLOYEE may be further grouped into:

• SECRETARY, ENGINEER, TECHNICIAN, …– Based on the EMPLOYEE’s Job

• MANAGER– EMPLOYEEs who are managers

• SALARIED_EMPLOYEE, HOURLY_EMPLOYEE– Based on the EMPLOYEE’s method of pay

• EER diagrams extend ER diagrams to represent these additional subgroupings, called subclasses or subtypes

Page 3: Uml

Subclasses and Superclasses

Page 4: Uml

Subclasses and Superclasses (2)

• Each of these subgroupings is a subset of EMPLOYEE entities

• Each is called a subclass of EMPLOYEE • EMPLOYEE is the superclass for each of these subclasses • These are called superclass/subclass relationships:

– EMPLOYEE/SECRETARY– EMPLOYEE/TECHNICIAN– EMPLOYEE/MANAGER– …

Page 5: Uml

Subclasses and Superclasses (3)• These are also called IS-A relationships

– SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, ….

• Note: An entity that is member of a subclass represents the same real-world entity as some member of the superclass:– The subclass member is the same entity in a distinct specific

role

Page 6: Uml

Representing Specialization in EER Diagrams

Page 7: Uml

Attribute Inheritance in Superclass / Subclass Relationships

• An entity that is member of a subclass inherits – All attributes of the entity as a member of the

superclass – All relationships of the entity as a member of the

superclass• Example:

– In the previous slide, SECRETARY (as well as TECHNICIAN and ENGINEER) inherit the attributes Name, SSN, …, from EMPLOYEE

– Every SECRETARY entity will have values for the inherited attributes

Page 8: Uml

Specialization (1)

• Specialization is the process of defining a set of subclasses of a superclass

• The set of subclasses is based upon some distinguishing characteristics of the entities in the superclass– Example: {SECRETARY, ENGINEER, TECHNICIAN} is

a specialization of EMPLOYEE based upon job type.• May have several specializations of the same superclass

Page 9: Uml

Specialization (2)

• Example: Another specialization of EMPLOYEE based on method of pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}.– Superclass/subclass relationships and specialization can be

diagrammatically represented in EER diagrams– Attributes of a subclass are called specific or local attributes.

• For example, the attribute TypingSpeed of SECRETARY– The subclass can also participate in specific relationship

types.• For example, a relationship BELONGS_TO of

HOURLY_EMPLOYEE

Page 10: Uml

Specialization (3)

Page 11: Uml

Generalization• Generalization is the reverse of the specialization process • Several classes with common features are generalized into

a superclass; – original classes become its subclasses

• Example: CAR, TRUCK generalized into VEHICLE; – both CAR, TRUCK become subclasses of the superclass

VEHICLE.– We can view {CAR, TRUCK} as a specialization of

VEHICLE – Alternatively, we can view VEHICLE as a generalization of

CAR and TRUCK

Page 12: Uml

Generalization (2)

Page 13: Uml

Generalization and Specialization (1)

• Diagrammatic notation are sometimes used to distinguish between generalization and specialization– Arrow pointing to the generalized superclass represents

a generalization – Arrows pointing to the specialized subclasses represent

a specialization – We do not use this notation because it is often

subjective as to which process is more appropriate for a particular situation

– We advocate not drawing any arrows

Page 14: Uml

Generalization and Specialization (2)

• Data Modeling with Specialization and Generalization– A superclass or subclass represents a collection (or set

or grouping) of entities– It also represents a particular type of entity– Shown in rectangles in EER diagrams (as are entity

types) – We can call all entity types (and their corresponding

collections) classes, whether they are entity types, superclasses, or subclasses

Page 15: Uml

Displaying an attribute-defined specialization in EER diagrams

Page 16: Uml

Relationships

• Relationships between entities can be optional or compulsory.

• Total participation• Partial participation• In an ER diagram, we indicate total participation with a

double line between the entity box and the relationship diamond.

Page 17: Uml

Total Participation

Page 18: Uml

Example

Page 19: Uml

Partial Participation

Page 20: Uml

Example

Page 21: Uml

Example• We could decide that a person is considered to be a customer

only if they have bought a product. On the other hand, we could say that a customer is a person whom we know about and whom we hope might buy something—that is, we can have people listed as customers in our database who never buy a product.

• In the first case, the customer entity has total participation in the bought relationship (all customers have bought a product, and we can’t have a customer who hasn’t bought a product), while in the second case it has partial participation (a customer can buy a product). These are referred to as the participation constraints of the relationship.

Page 22: Uml

Participation Constraints

• Recall that a key constraint requires that each entity of a set be required to participate in at most one relationship. Dual to this, we may ask whether each entity of a set be required to participate in at least one relationship. If this is required, we call this a total participation constraint; otherwise the participation is partial. In our ER diagrams, we will represent a total participation constraint by using a double or thick line.

Page 23: Uml

Example

Page 24: Uml

UML

Page 25: Uml

What is UML?

The Unified Modeling Language (UML) is a standard  language for specifying, visualizing, constructing, and documenting the artifacts of software systems, as well as for business modeling and other non-software systems. The UML represents a collection of best engineering practices that have proven successful in the modeling of large and complex systems.   The UML is a very important part of developing object oriented software and the software development process.  The UML uses mostly graphical notations to express the design of software projects.  Using the UML helps project teams communicate, explore potential designs, and validate the architectural design of the software.

Page 26: Uml

Goals of UML• The primary goals in the design of the UML were:• Provide users with a ready-to-use, expressive visual modeling

language so they can develop and exchange meaningful models. • Provide extensibility and specialization mechanisms to extend the

core concepts. • Be independent of particular programming languages and

development processes. • Provide a formal basis for understanding the modeling language. • Encourage the growth of the OO tools market. • Support higher-level development concepts such as collaborations,

frameworks, patterns and components. • Integrate best practices.

Page 27: Uml

Why Use UML?

• As the strategic value of software increases for many companies, the industry looks for techniques to automate the production of software and to improve quality and reduce cost and time-to-market. These techniques include component technology, visual programming, patterns and frameworks. Businesses also seek techniques to manage the complexity of systems as they increase in scope and scale. In particular, they recognize the need to solve recurring architectural problems, such as physical distribution, concurrency, replication, security, load balancing and fault tolerance. Additionally, the development for the World Wide Web, while making some things simpler, has exacerbated these architectural problems. The Unified Modeling Language (UML) was designed to respond to these needs.

Page 28: Uml

Types of UML Diagrams

• Use Case Diagram: displays the relationship among actors and use cases.1

• Class Diagram: models class structure and contents using design elements such as classes, packages and objects. It also displays relationships such as containment, inheritance, associations and others. 1

• Interaction diagrams– Sequence Diagram displays the time sequence of the objects

participating in the interaction. This consists of the vertical dimension (time) and horizontal dimension (different objects).1

– Collaboration Diagram displays an interaction organized around the objects and their links to one another. Numbers are used to show the sequence of messages.1

Page 29: Uml

Class diagrams

• Class diagrams are widely used to describe the types of objects in a system and their relationships. 

•  Class diagrams describe three different perspectives when designing a system, conceptual, specification, and implementation.  These perspectives become evident as the diagram is created and help solidify the design. 

Page 30: Uml

Classes

• Classes are composed of three things: – a name, – attributes, and – operations. Below is an example of a class.

Page 31: Uml

UML Class Diagram

• Represent classes (similar to entity types) as large rounded boxes with three sections:– Top section includes entity type (class) name– Second section includes attributes– Third section includes class operations (operations are not in

basic ER model)• Relationships (called associations) represented as lines

connecting the classes– Other UML terminology also differs from ER terminology

• Used in database design and object-oriented software design

Page 32: Uml

Relationship

• The association relationship is the most common relationship in a class diagram. 

• The association shows the relationship between instances of classes. 

Page 33: Uml

Example

• For example, the class Order is associated with the class Customer. • The multiplicity of the association denotes the number of objects that can

participate in then relationship.

• For example, an Order object can be associated to only one customer, but a customer can be associated to many orders. 

Page 34: Uml
Page 35: Uml

Class Hierarchies

• As with object-oriented programming, it is often convenient to classify an entity sets as a subclass of another. In this case, the child entity set inherits the attributes of the parent entity set. We will denote this scenario using an "ISA" triangle, as in the next slide ER diagram:

Page 36: Uml

ER diagram

Page 37: Uml

Aggregation

• Define new relationship which associates some entity with some other existing relationship. To do this, we will introduce a new feature to our model called aggregation.

• Identifying an existing relationship set by enclosing it in a larger dashed box, and then we will allow it to participate in another relationship set.

Page 38: Uml

Example

Page 39: Uml

ER Model for library information system

• Entity type BOOK(ISBN,title,author,publisher,date-of-pub,{keywords}) Notice {keywords} is a multi-valued attribute. The key is ISBN. Entity type STUDENT(SSN,fname,lname,address,telephone) The key is SSN.

• Relation type BORROW(SSN,ISBN,date-of-borrow,no-of-renewal,fine)

• The BORROW relation type is one-to-many. Participation of BOOK is partial Participation of STUDENT is partial

Page 40: Uml