Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

Similar documents
Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

UML & OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 3 09/04/2012

Credit where Credit is Due. Last Lecture. Goals for this Lecture

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

Chapter 11 Object and Object- Relational Databases

Appendix Fundamentals of Object Technology

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Credit where Credit is Due. Goals for this Lecture. Introduction to Design

Unified Modeling Language (UML) Class Diagram

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007

MechEng SE3 Lecture 7 Domain Modelling

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects,

Introduction to Software Engineering. 5. Modeling Objects and Classes

LABORATORY 1 REVISION

OOAD - OBJECT MODEL. The concepts of objects and classes are intrinsically linked with each other and form the foundation of object oriented paradigm.

Object-Oriented Software Engineering Practical Software Development using UML and Java

Software Design Models, Tools & Processes. Lecture 3: Addendum Cecilia Mascolo

SOFTWARE ENGINEERING Prof.N.L.Sarda Computer Science & Engineering IIT Bombay. Lecture #10 Process Modelling DFD, Function Decomp (Part 2)

Object-Oriented Design

CMPT 354 Database Systems I

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

administrivia today UML start design patterns Tuesday, September 28, 2010

Class Diagram. Classes consist of. Note that class diagrams contain only classes, not objects.

Chapter 2: Entity-Relationship Model

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009

Class Diagram. Classes consist of. Note that class diagrams contain only classes, not objects.

OO System Models Static Views

Inheritance and Polymorphism

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

Chapter 6: Entity-Relationship Model

Introduction to Unified Modelling Language (UML)

Introduction to Software Engineering. 5. Modeling Objects and Classes

Module 2 : Entity-Relationship Model 15

Introducing the UML Eng. Mohammed T. Abo Alroos

Class modelling (part 2)

Object-Oriented Design

COMP Instructor: Dimitris Papadias WWW page:


MIS Database Systems Entity-Relationship Model.

Unified Modeling Language (UML)

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

For 100% Result Oriented IGNOU Coaching and Project Training Call CPD TM : ,

The Entity-Relationship Model. Steps in Database Design

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

OO Techniques & UML Class Diagrams

What are the characteristics of Object Oriented programming language?

Introduction to OO Concepts

Chapter 7: Entity-Relationship Model

2004 John Mylopoulos. The Entity-Relationship Model John Mylopoulos. The Entity-Relationship Model John Mylopoulos

Java Object Oriented Design. CSC207 Fall 2014

CSIT5300: Advanced Database Systems

Chapter 7: Entity-Relationship Model

Database Applications (15-415)

Chapter 2: The Object-Oriented Design Process

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Chapter 6: Entity-Relationship Model

Object-Oriented and Classical Software Engineering

Computer Science for Engineers

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 5: Modelling with Classes

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

OBJECT ORİENTATİON ENCAPSULATİON

Chapter 7: Entity-Relationship Model

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis

Relationships. Association Aggregation/Composition Multiplicity Dependencies

Inheritance and Interfaces

Entity Relationship Modelling

UML Class Diagrams Revisited

UML Fundamental. OutLine. NetFusion Tech. Co., Ltd. Jack Lee. Use-case diagram Class diagram Sequence diagram

UML Views of a System

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Chapter 3 Database Modeling and Design II. Database Modeling

Class modelling (part 2)

Class diagrams. Modeling with UML Chapter 2, part 2. Class Diagrams: details. Class diagram for a simple watch

CIS 330: Web-driven Web Applications. Lecture 2: Introduction to ER Modeling

Conceptual Design with ER Model

Chapter 6: Entity-Relationship Model

Roadmap of This Lecture. Weak Entity Sets Extended E-R Features Reduction to Relation Schemas Database Design UML*

Object Oriented Software Development CIS Today: Object Oriented Analysis

Chapter 7: Entity-Relationship Model

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

XV. The Entity-Relationship Model

Chapter 6 Introduction to Defining Classes

Software Service Engineering

Object- Oriented Design with UML and Java Part I: Fundamentals

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

ACS-3913 Ron McFadyen 1. UML Notation for Class diagrams Object diagrams

Pertemuan 8. Object Oriented Modeling and Design

COP 3330 Final Exam Review

Enhanced Entity- Relationship Models (EER)

Data Analysis 1. Chapter 2.1 V3.1. Napier University Dr Gordon Russell

Chapter 5: Structural Modeling

Lecture 5: Inheritance

Object Fundamentals. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007

Design Engineering. Dr. Marouane Kessentini Department of Computer Science

Transcription:

Lecture 4: Fundamentals of Object Technology Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Credit where Credit is Due Some material presented in this lecture is taken from section 2.1 of Maciaszek s Requirements Analysis and System Design. Addison Wesley, 2000 January 23, 2003 University of Colorado, 2003 2 Goals for this Lecture Introduce fundamental object-oriented concepts classes, objects, attributes, methods, associations, encapsulation, inheritance, polymorphism, etc. to lay the foundation for using these concepts in object-oriented analysis Real-World Objects The world consists of objects in a particular state a full coffee mug a tired athlete Some objects exhibit behavior a dog barks All objects have identity a property that allows us to distinguish one object from another January 23, 2003 University of Colorado, 2003 3 January 23, 2003 University of Colorado, 2003 4

More on identity If we examine two cups from the same set of china, we may say that the cups are equal but not identical They are equal because they have the same set of attributes (size, shape, color, ) and they have the same values for each of their attributes but they are two distinct cups and we can select among them; no two objects can have the same identity (otherwise they would be the same object) Artificial and Natural Systems Since natural systems consist of objects and can exhibit complex behavior perhaps we can construct artificial systems by emulating the structure and behavior of natural systems The object-oriented approach to software development is based on this premise; we model the real world using objects the behavior and state of these objects capture the information of real-world tasks we implement systems with these objects to support the automation of the modeled tasks January 23, 2003 University of Colorado, 2003 5 January 23, 2003 University of Colorado, 2003 6 Instance Object An object is an instance of a class A class is a generic description of all of its possible instances in particular it specifies the set of attributes its objects possess and the set of behaviors its objects can perform Note: we sometimes need an object that represents a class, or a class object this enables reflection the ability for objects to ask questions about their own characteristics, such as how many operations do I have? and attributes and operations that are not associated with any particular instance of a class but with the class itself Object Notation The UML notation for an object is a rectangle with two compartments the upper compartment specifies an object s name and its class separated by a colon; both are underlined Ken : Employee -- an object Ken of the Employee class Ken : -- an object whose type is not known : Employee -- an unnamed object the lower compartment lists the values the object has for its attributes January 23, 2003 University of Colorado, 2003 7 January 23, 2003 University of Colorado, 2003 8

Object Notation, continued Ken : Employee Name = Ken Start_Date = Fall 1998 Object Collaboration The number of instances for a class can be very large as such objects are rarely drawn Typically, they are only drawn to demonstrate how certain objects collaborate over time to accomplish a task Tasks are performed by objects invoking operations (behavior) on each other an operation is invoked by passing the target operation a message, aka message passing January 23, 2003 University of Colorado, 2003 9 January 23, 2003 University of Colorado, 2003 10 Object Collaboration, cont. Object Collaboration, cont. A message specifies the name of an operation and provides values for that operation s parameters (if any) Once invoked, the operation may result in a change of state or a change in an object s attribute values it may lead to the target object invoking operations on additional objects :Order 1: shiporder() 2: subtractproducts() 3: analyzestocklevels() :Shipment :Stock 4: reorderproducts() :Purchase An Order object requests a Shipment object to ship its products. To do so, the Shipment object instructs the Stock object to decrease its inventory; later the Stock object may analyze its inventory levels and reorder any required products January 23, 2003 University of Colorado, 2003 11 January 23, 2003 University of Colorado, 2003 12

Identifying Objects How does an object learn the identity of an object to which it wants to send a message? How does the Order object find the Shipment object in order to send the shiporder message? Each object is given an object identifier (OID) when it is created this identifier is a unique number that remains with the object for its entire life (from the time it s created until it s destroyed) So, the OID of the Shipment object must be passed to the Order object; how is this done? January 23, 2003 University of Colorado, 2003 13 Identifying Objects, continued A link provides a means for one object to know the OID of another object links can be persistent or transient The type of link used in a given situation depends on the longevity of objects transient objects live only as long as a program executes persistent objects outlive the execution of the program; they are stored persistently to be accessed on subsequent program runs January 23, 2003 University of Colorado, 2003 14 Identifying Objects, continued A persistent link is an object reference in a persistent object to another persistent object Hence, to persistently link a Course object to a Teacher object, both objects must be persistent and the OID of the Teacher object must be stored in the Course object as the value of a link attribute January 23, 2003 University of Colorado, 2003 15 A Persistent Link c : Course Ref345 Name = CSCI 6448 teacher = Ref123 t : Teacher Name = Ken Ref123 The Course object has an attribute named teacher that stores a reference to the OID of its instructor. Both the Course and Teacher objects are persistent. This is indicated by placing their OIDs in the upper right hand corner of their object representations. When these objects are written to disk, the reference in Course is saved too. When these objects are read from disk, the reference in Course is once again set to the OID of the Teacher object; In this particular set-up, only the Course object can invoke operations on the Teacher object, the Teacher object is unaware of the existence of the Course object. January 23, 2003 University of Colorado, 2003 16

A Persistent Link, continued c : Course Name = CSCI 6448 Teaches course teacher t : Teacher Name = Ken During analysis and design, we rarely care about the specific OIDs of objects; instead we care about the relationships that exist between objects; As such a persistent link is represented in the UML as an instance of an association that exists between the object s classes; Here we show that Teacher and Course objects participate in a teaches association with two roles, than can be used to navigate the association from one end to the other. Note, in the previous slide only the Course object could call on the Teacher object; on this slide, we have delayed that decision, this notation allows either object to call upon the other (there are ways to specify the direction of an association which we will cover later in the semester) January 23, 2003 University of Colorado, 2003 17 Transient Links Transient links are similar to persistent links, except that the link is established at run-time and is not made persistent Thus, if I have multiple Course objects and I loop over them Then, the loop variable is temporarily storing the OID for each Course object and establishing a transient link to a new Course object for each iteration of the loop January 23, 2003 University of Colorado, 2003 18 Classes Class Notation A class is a generic descriptor for a set of objects that have the same attributes and operations It serves as a template for object creation Each object created from the template has space allocated for each attribute specified in the template and can invoke the operations defined in its class The notation for a class is a rectange with three compartments; one for the name, one for attributes, and one for operations the UML actually defines four compartments; we will discuss the fourth compartment later in the semester January 23, 2003 University of Colorado, 2003 19 January 23, 2003 University of Colorado, 2003 20

Attributes An attribute is a type-value pair Classes define attribute types Objects contain attribute values An attribute can be a built-in primitive type (that is supplied by an object-oriented programming language) or it can be another class In objects, an attribute with a class-based type contain OIDs to objects of the specified class In UML, class-based attributes are not listed in the attribute compartment, instead they are represented as associations January 23, 2003 University of Colorado, 2003 21 Attribute Visibility Not all attributes (and operations) are available to objects who have a link to another object The visibility of an attribute determines who can access and manipulate the value of the attribute private visibility (indicated by prefixing the attribute name with a minus sign) means that the attributes can only be manipulated by instances of that class public visibility (indicated by prefixing the attribute name with a plus sign) means that the attributes can be manipulated by instances of all classes there is also protected visibility, which we will discuss later January 23, 2003 University of Colorado, 2003 22 Attribute Visibility, continued Most operations are public, but most attributes are private Operations are said to encapsulate attributes; protect them from being changed in unauthorized ways This is important since a class may have a set of attributes that need to be updated in tandem if an object of another class changes an object s attribute, it may not know to update the values of the other associated attributes This can cause an object s values to get out of synch and potentially lead to system failures January 23, 2003 University of Colorado, 2003 23 Operations An operation is an algorithm that acts on attributes Operations are implemented by methods Operations are invoked by messages or events the name of the message and the name of the invoked operation are the same a message can pass parameter data to an operation and an operation can return a value to the object that sent the message The name of an operation together with a list of its parameter types is called the operation s signature A signature must be unique within a class; this means that a class can have multiple operations with the same name just as long as their parameter types are different January 23, 2003 University of Colorado, 2003 24

Operation Visibility and Scope Operation visibility is the same as attribute visibility; it determines if objects of other classes can see and invoke an object s operations Operation scope is a distinct concept that determines if an operation acts on objects (instance scope) or class objects (class scope) Example in textbook: The age of an employee vs. the average age of all employees Associations An association is a type of relationship between classes other types of relationships include generalization, aggregation, dependency, etc. As we have seen, associations govern the linkage between objects of particular classes January 23, 2003 University of Colorado, 2003 25 January 23, 2003 University of Colorado, 2003 26 Associations, continued Association degree defines the number of classes that can be connected by an association A binary association is the most common, although unary and ternary associations can be specified (see page 38) Association multiplicity defines how many objects may fill the position identified by a role name The multiplicity states how many objects of the target class can be associated with a single object of the source class Multiplicity Example To interpret a multiplicity always assume a 1 is at the opposite end of the association, for example, a person may have only one employer a company may have one or more employees Person 1..* 1 employee employer Company The multiplicity is shown as a range of integers n1..n2. n1 defines the minimum number of connected objects, while n2 defines the maximum number; page 39 shows common multiplicities January 23, 2003 University of Colorado, 2003 27 January 23, 2003 University of Colorado, 2003 28

Association Class Sometimes an association has attributes and/or operations of its own Such an association must be modeled as a class (because attributes can only be defined in a class) Company Job Person Aggregation and Composition Aggregation is a whole-part relationships between a class representing an assembly of components and the classes representing the components themselves The containment property can be strong (containment by value) or weak (containment by reference) In the UML, containment by value is known as composition January 23, 2003 University of Colorado, 2003 29 January 23, 2003 University of Colorado, 2003 30 Aggregation/Composition, cont. In modeling, aggregation is a special kind of association which is transitive and asymmetric Transitive: If A contains B and B contain C, then A contains C Asymmetric: If A contains B, then B cannot contain A Composition has an additional constraint of existence dependency If the container is deleted, its contents are deleted as well; the contents cannot exist without being contained January 23, 2003 University of Colorado, 2003 31 Examples * Aggregation: Crate Bottle * Composition: Book Chapter January 23, 2003 University of Colorado, 2003 32

Generalization Generalization is a kind-of relationship between a more generic class (superclass or parent) and a more specialized class (subclass or child) Since a subclass is a particular type of the superclass, an object of the subclass can be used anywhere an object of the superclass is allowed Generalization, continued Subclasses may reuse any of the attributes and operations defined by its superclass (it is said to inherit these features from the superclass) A generalization is notated with a hollow triangle on a line connecting the superclass and subclass January 23, 2003 University of Colorado, 2003 33 January 23, 2003 University of Colorado, 2003 34 Example Polymorphism Generalization Shape Rectangle Square An instance of Square will contain all the attributes and operations defined for Square, Rectangle, and Shape; Any place a Shape object can be used in a program, a Square object can be substituted (since it has the same attributes and operations that Shape does) January 23, 2003 University of Colorado, 2003 35 An inherited operation from a superclass can be overridden (modified) in a subclass to correspond to semantic variations of the subclass For instance, calculateperimeter() will be implemented differently in Square than it would be for Circle() This is indicated by placing a superclass operation with the same name and parameters in the subclass Calls to such methods are polymorphic (many forms) in that the most specific implementation of the method will be invoked based on the class of the target object January 23, 2003 University of Colorado, 2003 36

Polymorphism, continued Thus, if we have an array of Shape objects, in which some objects are Squares and some are Circles, the following code can correctly calculate the sum of all their perimeters for (i = 1; i < shapes.length; i++) { Shape s = shapes[i]; totalperimeter += s.getperimeter() } Note that we call getperimeter() on a Shape object, but if the shape is a Square then it is Square s getperimeter() method that executes and likewise if the shape is a Circle then Circle s getperimeter() executes January 23, 2003 University of Colorado, 2003 37 Multiple Inheritance Some object-oriented programming languages will allow a subclass to inherit from multiple superclasses A diamond in the inheritance structure can cause problems; consider Figure 2.19 on page 44 of the textbook An instance of Tutor inherits the attributes and operations of Person twice; these situations are typically difficult to handle January 23, 2003 University of Colorado, 2003 38 Multiple Inheritance, continued In addition, a problem arises if a superclass is specialized into multiple orthogonal hierarchies; because with multiple inheritance while a class can have multiple superclasses; an object must be an instance of a single class so if I want an instance of a Person, who inherits from the Child, Female, and Student classes, I need to create a single class called ChildFemaleStudent if the number of orthogonal hierarchies is large, an explosion in the number of classes can result January 23, 2003 University of Colorado, 2003 39 Multiple Classificiation Multiple classification is a solution to this problem; it simply states that objects are allowed to be instances of more than one class; Unfortunately, not many object-oriented programming languages support multiple classification Some languages provide the concept of an interface, which partially addresses this problem without resorting to multiple classification, except that with interfaces, no method implementations can be shared among objects that implement the same interface January 23, 2003 University of Colorado, 2003 40

Dynamic Classification Dynamic Classification allows an object to switch classes during its life-time again, unfortunately, most object-oriented programming languages do not support dynamic classification This concept is useful in tracking changes to a long-lived object For instance a Programmer object may need to change into a Manager object Abstract Class An abstract class is a parent class that cannot be directly instantiated the reason for this is that all or some of its operations have undefined methods An abstract class is often used to specify a contract that subclasses must follow for a particular task When a subclass is defined, it provides method implementations for each of the parent s abstract methods that help it fulfill the contract For instance, a Shape object may define many abstract methods that allow Shapes to be moved and manipulated; a shape subclass cannot be instantiated until it provides methods for each abstract method January 23, 2003 University of Colorado, 2003 41 January 23, 2003 University of Colorado, 2003 42 What s Next This lecture: fundamental objectoriented concepts Next lecture: Introduction to Analysis After that Structured Analysis Techniques to show how they contrast with OO approaches Object-Oriented Analysis Techniques Use Cases January 23, 2003 University of Colorado, 2003 43