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

Similar documents
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

Allenhouse Institute of Technology (UPTU Code : 505) OOT Notes By Hammad Lari for B.Tech CSE V th Sem

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Introduction to Software Engineering. 5. Modeling Objects and Classes

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

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )

1. Write two major differences between Object-oriented programming and procedural programming?

Object-Oriented Programming Paradigm

Prepared By:Mitali sonar

LABORATORY 1 REVISION

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

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

Introducing the UML Eng. Mohammed T. Abo Alroos

UML REFERENCE SHEETS. 2013, 2014 Michael Marking; all rights reserved, including moral rights. Web site:

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

What are the characteristics of Object Oriented programming language?

Object oriented programming Concepts

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

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Object Orientated Analysis and Design. Benjamin Kenwright

Object Oriented Modeling and Design

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

What is a Data Model?

Software Service Engineering

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Vidyalankar. T.Y. Diploma : Sem. VI [IF/CM] Object Oriented Modeling and Design Prelim Question Paper Solution

UNIT V *********************************************************************************************

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

Software Architecture (Lesson 2) Object-Oriented Paradigm (1)

CMPT 354 Database Systems I

Inheritance and Interfaces

12 Tutorial on UML. TIMe TIMe Electronic Textbook

Modeling Databases Using UML

Unified Modeling Language

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

SE 1: Software Requirements Specification and Analysis

Introduction to Software Engineering. 5. Modeling Objects and Classes

CHAPTER 5 CO:-Sketch component diagram using basic notations 5.1 Component Diagram (4M) Sample Component Diagram 5.2 Deployment Diagram (8M)

Developing Shlaer-Mellor Models Using UML

Chapter 4. Enhanced Entity- Relationship Modeling. Enhanced-ER (EER) Model Concepts. Subclasses and Superclasses (1)

Object-Oriented Design

Software Engineering Lab Manual

Basic Structural Modeling. Copyright Joey Paquet,

OBJECT ORİENTATİON ENCAPSULATİON

Chapter 2: Entity-Relationship Model

CSE 403: Software Engineering, Spring courses.cs.washington.edu/courses/cse403/15sp/ UML Class Diagrams. Emina Torlak

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

UNIT-4 Behavioral Diagrams

Chapter 8: Class and Method Design

Unit II. Advanced Structural Modeling

Chapter (4) Enhanced Entity-Relationship and Object Modeling

UNIT-II Introduction to UML

Chapter 11 Object and Object- Relational Databases

COSC 3351 Software Design. An Introduction to UML (I)

Object-Oriented Systems Analysis and Design Using UML

Full file at Chapter 2: Foundation Concepts

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Chapter 8: Creating Your Own Type Classes

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

UML Tutorial. Unified Modeling Language UML Tutorial

Pertemuan 8. Object Oriented Modeling and Design

Enhanced Entity-Relationship (EER) Modeling

Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques. Fundamentals, Design, and Implementation, 9/e

Introduction to Unified Modelling Language (UML)

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

CS211 Lecture: Relationships Between Classes: Dependency, Inheritance, and Realization

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

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

UNIT 5 - UML STATE DIAGRAMS AND MODELING

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

Object Oriented Design. Program Design. Analysis Phase. Part 2. Analysis Design Implementation. Functional Specification

Chapter 1: Principles of Programming and Software Engineering

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

user.book Page 45 Friday, April 8, :05 AM Part 2 BASIC STRUCTURAL MODELING

CPS 506 Comparative Programming Languages. Programming Language

Practical UML - A Hands-On Introduction for Developers

Object Model. Object Orientated Analysis and Design. Benjamin Kenwright

Class modelling (part 2)

UCLA PIC 20A Java Programming

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Inheritance and Substitution (Budd chapter 8, 10)

UML Class Diagrams Revisited

SOFTWARE ENGINEERING UML FUNDAMENTALS. Saulius Ragaišis.

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

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

UNIT II. Syllabus. a. An Overview of the UML: Visualizing, Specifying, Constructing, Documenting

Chapter 6 Introduction to Defining Classes


Chapter 10 Object-Oriented Design Principles

Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques. Fundamentals, Design, and Implementation, 9/e

OMG Modeling Glossary B

Database Design Process

Object-Oriented Systems Development: Using the Unified Modeling Language

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

Class modelling (part 2)

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

Transcription:

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects, Classes, Class Diagrams Values and Attributes Operations and Methods Link and Association concepts -Links and Associations,Multiplicity, Association and Names, Ordering Association Classes, Qualified Association Generalization and Inheritance -Use of Generalization, Sample Class Model 2.2 Multiplicity, Aggregation and Object Modeling (12M) Multiplicity, Aggregation Aggregation Versus Association Propagation of operations Multiple Inheritance,Metadata and Constraints-Metadata,Constraints on objects and links Object modeling Object instances Sample Object Model Objects: An object can be a variable, a data structure, or a function. An object is a real time entity. An object is a variable of type class. In class-based object-oriented programming paradigm, "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures Properties of Object: Identity that distinguishes it from other objects in the system. State that determines the characteristic properties of an object as well as the values of the properties that the object holds. Behavior that represents externally visible activities performed by an object in terms of changes in its state. Objects can be modeled according to the needs of the application. All objects are having identity and are distinguishable. A Car, a Person, a house are examples of object. e.g. An object may have a physical existence, like a customer, a car, etc.; or an

intangible conceptual existence, like a project, a process, etc Dogs have state (name, color, and breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.

Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. Bundling code into individual software objects provides a number of benefits, including: Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system. Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world. Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task- specific objects, which you can then trust to run in your own code. Plug ability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine. Classes In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). A class is a group of objects with similar properties, common behavior, and common relationship. Classes should be defined by an informative statement of purpose and scope. Class names are critical for ease of communication. Strive for crisp, clear, and direct naming. Fig: Examples of class

Class Diagrams The class diagram is a static diagram. It represents the static view of an application. Class diagram is not only used for visualizing, describing and documenting different aspects of a system but also for constructing executable code of the software application. The class diagram describes the attributes and operations of a class and also the constraints imposed on the system. The class diagrams are widely used in the modeling of object oriented systems because they are the only UML diagrams which can be mapped directly with object oriented languages. The class diagram shows a collection of classes, interfaces, associations, collaborations and constraints. It is also known as a structural diagram. Purpose of class diagram The purpose of class diagram is to model the static view of an application. Class diagrams are the only diagrams which can be directly mapped with objectoriented languages and thus widely used at the time of construction. UML diagrams like activity diagram, sequence diagram can only give the sequence flow of the application; however class diagram is a bit different. It is the most popular UML diagram in the coder community. The purpose of the class diagram can be summarized as Analysis and design of the static view of an application. Describe responsibilities of a system. Base for component and deployment diagrams. Forward and reverse engineering Notations for class diagrams 1. Class

A class is a group of objects with similar properties, common behavior, and common relationship. Class consist of attribute and operations. Notations of class is as shown below Fig : Class notation 2. Attributes An attributes is a named property of a class that describes a value held by each object of the class. A class may have any number of attributes or no attributes at all. An attribute represents some property of the thing that is shared by all the objects of that class. Attributes are listed in the second part of Class Box. Each attribute name may be followed by optional details. Each attribute name is unique within a class. For Example: Class Person has attributes Name, Birthdate and weight. Name is string, Birthdate is Date and Weight is integer. Attributes should be: Complete - capture all information relevant to the class being defined. fully factored - each attribute captures a separate aspect of the class abstraction Mutually independent - attributes take on values independent of each other. Note: Dependent attributes (or derived attributes) may be Introduced to facilitate performance. Attribute can be classified as Descriptive attributes - Provide facts intrinsic to each instance of the class Naming attributes - Provide facts about the labels and names carried by an object (class instance) Classifying attributes - Capture the facts, which tie an object to Another object of a different class. Link Attribute with respect to class or object Link attribute specify properties of link/association between two classes/objects. For example: In the below example company and person has a

Link/association between them which has link attributes as description, date hired and salary. These attributes are placed inside the association Class job. Association class is linked to association line with dashed line Fig: Link attribute 3. Operations and Methods All objects in a class share the same operations. A method is animplementation of an object for a class. Each operation has a target object as an implicit argument, andoptionally, input and output arguments. The same operation may apply to different classes. This is the foundation of polymorphism. To exploit polymorphism, operations on more than one classshould have consistent intent (semantics) and the same signature (number and types of input and output arguments). As with classes, naming is important. Avoid using the same namefor two operations that are semantically different. 4. Associations and Links Links and associations are the means for establishingrelationships among objects and classes

When an association connects two classes you can navigate from one object of one class to an object of another class and vice versa. Graphically an association is represented as a solid line connecting more than one class. Links are physical or conceptual connections between objectinstances. An association describes a group of links with a common structureand common semantics. Links are instances of associations. An association describes a set of potential links in the same waythat a class describes a set of potential objects. Associations are inherently bi-directional. Associations are typically binary, but may be of any higher order. Associations are often left unnamed when they can be easilyidentified by their classes. This can, however, lead to ambiguity. 5. Multiplicity Multiplicity refers to how many instances of one class may relate to a single instance of an associated class. Determine classes and associations before deciding on multiplicity. Multiplicity is represented by symbols at the end of an association.here are the various possibilities. 1. 1 exactly one 2. 1...* One or more 3. 3-5 three to five 4. 0..1 zero to one 5. 2,4,18 two, four or eighteen 6. Symbol * denotes many 6. Qualification/Qualified Association A qualified association relates two object classes and a qualifier. Itis an attribute that reduces the effective multiplicity of anassociation by identifying a single target object.

Qualified associations improve semantic accuracy and increase thevisibility of navigation paths. A qualified association is equivalent to the concepts known asassociative arrays, maps, and dictionaries. 7. Role Name A role name is a name that uniquely identifies one end of an association. Each role on an association identifies an object or set of objects associated with an object at the other end. The role name clarifies the purpose an object serves in an association. Role names are necessary for associations between two objects of the same class. For example, a directory can contain other directories. Roles help clarify this association.

8. Ordered association An "{ordered}" annotation is used to denote that a collection of objects is "ordered". Otherwise, a collection of objects is assumed to have no particular order. Usually the objects on the "many" side of an association have no explicit order, and can be regarded as a set. Sometimes the objects on the many side of an association have order. Writing {ordered} next to the multiplicity dot indicates an ordered set of objects of an association. Notation and example

9. Association Class Class Association sometimes has operations and attributes to show such association and to define the features of an association we use association classes. For example, if I say draw a class diagram for a student taking courses then class diagram would include only two classes "Students" and "Courses" and there will be a simple association between them with many to many multiplicity, means students can take zero or more courses and on other hand courses can have zero or many students. See diagram below: Now, if I change the system requirements a little and tell you that now the system records assessment of each course the student take and send the assessment report to students later on. In this case our association has operation that is to send assessment report and some attributes, let s say grade obtained and total marks. Now we are required to use an association class to show the features of the association we have between students and courses and our class diagram would look something like this:

10. Generalization and Inheritance Generalization: It is also referred as is-a relationship. It is relationship between a class (super class) and one or more variations of the class (sub classes). It organizes classes by their similarities and differences, structuring the description of objects. The super class holds common attributes, operations and association. The subclasses add specific attributes, operations and associations. Each sub class inherits the features of its super class. Notation: A large hollow arrowhead is used to show generalization. The arrowhead points towards the super class. Example of generalization "Savings account IS AN Account" Square IS A shape Inheritance:- It is the mechanism of inheriting features of super class in its subclass. Inheritance provides reusability of code where code declared for super class can be used by its sub class. Example:

Multiple Inheritance Multiple Inheritance permits a class to have more than one superclass and to inherit features from all parents. Then you can mix information from two or more sources. This is a more complicated form of generalization than single inheritance, which restricts the class hierarchy to a tree. The advantage of multiple inheritances is greater power in specifying classes and an increased opportunity for reuse. The disadvantage is a loss of conceptual and implementation simplicity. Inheritance used for three purposes: Support of polymorphism: Polymorphism increases the flexibility of software. Adding a new subclass and automatically inheriting superclass behavior. Structuring the description of objects:

Forming taxonomy (classification), organizing objects according to their similarities. It is much more profound than modeling each class individually and in isolation of other similar classes. Enabling code reuse: Reuse is more productive than repeatedly writing code from scratch. 11. Aggregation Aggregation is a variant of the "has a" association relationship aggregation is more specific than association. It is an association that represents a part-whole or part-of relationship. Aggregation implies that an object is responsible for agroup of other objects. In comparison, an association link implies that an object knows ofanother object in the sense that they must interact in some capacity. The objects in an aggregation are independent, but are more tightlycoupled than through an ordinary association. Aggregation is transitive. That is, A is part of B, and B is part ofc, implies A is part of C. Aggregation is not symmetric. This is Ais part of B does not imply B is part of A. The semantics of aggregation are not precise When in doubt, model with associations. Use a consistent interpretation of aggregation in your models. Notation and example Fig.: Aggregation symbol E.g. Engine is a part of car 12. Composition Composition is a special case of aggregation. In a more specific manner, a restricted aggregation is called composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition. Notation and example

Aggregation vs. Association

13. Realization In UML modeling, a realization relationship is a relationship between two model elements, in which one model element (the client) realizes (implements or executes) the behavior that the other model element (the supplier) specifies Notation 14. Dependency It is a semantic relationship between two things in which change to one thing may affect the semantics of the other thing. Notation * Prapogation of opration Propagation is the automatic application of an operation to a network of objects when the operation is applied to some starting object. Propagation of operations to parts is often a good indicator of propagation. You can propagate operations through aggregation and composition. Figure shows an example of propagation. A person owns multiple documents. Each document consists of paragraphs that, in turn, consist of characters. The copy operation propagates from documents to paragraphs to

characters. Copying a paragraph copies all the characters in it. The operation does not propagate in the reverse direction; a paragraph can be copied without copying the whole document. Similarly, copying a document copies the owner link but does not spawn a copy of the person who is owner. Propagation of operation * Constraints A constraint is some condition, restriction or assertion related to some element (that owns the constraint) or several elements. Constraint is usually specified by a Boolean expression which must evaluate to a true or false. Constraint must be satisfied (i.e. evaluated to true) by a correct design of the system. Constraints are commonly used for various elements on class diagrams. Constraint could have an optional name, though usually it is anonymous. A constraint is shown as a text string in curly braces according to the following syntax: Constraint::= '{' [ name ':' ] boolean-expression '}' 1. Constraints on Objects: The structure of model expresses many constraints but sometimes it is helpful to add explicit constraints. Examples of some constraints are: 2. Constraints on Generalization Sets: Disjoint Overlapping Complete Incomplete

3. Constraints on Links: * Metadata "Metadata is "data about data". Structural metadata is about the design and specification of data structures and is more properly called "data about the containers of data" Descriptive metadata is about individual instances of application data, the data content. Metadata are traditionally found in the card catalogs of libraries. As information has become increasingly digital, metadata are also used to describe digital data using metadata standards specific to a particular discipline.

For example, a webpage may include metadata specifying what language it is written in, what tools were used to create it, and where to go for more on the subject, allowing browsers to automatically improve the experience of users. Purpose of Metadata For example, an image may include metadata that describes how large the picture is, the color depth, the image resolution, when the image was created, and other data. A text document's metadata may contain information about how long the document is, who the author is, when the document was written, and a short summary of the document. Meta data: - Metadata is data that describes other data.for example, the definition of a class is metadata. Models are inherently metadata, since they describe the things being modeled. A relational database management system use metadata. A person can define database tables for storing information.

Class diagram for ATM system

Class Diagram for railway reservation system Object modelling Object diagrams are derived from class diagrams so object diagrams are dependent upon class diagrams. Object diagrams represent an instance of a class diagram. The basic concepts are similar for class diagrams and object diagrams. Object diagrams also represent the static view of a system but this static view is a snapshot of the system at a particular moment. Object diagrams are used to render a set of objects and their relationships as an instance. Notations 1. Object: - An object is a concept, abstraction or thing that has meaning for an application. Object is basic run time entity. In UML object is represented with a box including its name followed by a colon and class name. Object and class name both are written in bold face with underline. Object can have attributes.

Attributes are specified in the second part of the block. Attribute name is followed by value. Notation Example 2. Link- It is physical or conceptual connection among objects. It is used to show relationship among objects. It is represented with a solid line connecting two objects. Name of the link is written in italic form above line. Example (Also write notations for relationships in class diagram) Draw object diagram for placing order