Review of Object Orientation
What is Object Orientation?
Procedural paradigm:
• Software is organized around the notion of procedures
• Procedural abstraction
• Works as long as the data is simple
• Adding data abstractions
• Groups together the pieces of data that describe some entity
• Helps reduce the system’s complexity.
• Such as Records and structures
Object oriented paradigm:
• Organizing procedural abstractions in the context of data abstractions
© Gurbakash Phonsa Object Oriented concept review 2
Object Oriented paradigm
An approach to the solution of problems in which all computations are
performed in the context of objects.
• The objects are instances of classes, which:
• are data abstractions
• contain procedural abstractions that operation on the objects
• A running program can be seen as a collection of objects collaborating to
perform a given task
© Gurbakash Phonsa Object Oriented concept review 3
A View of the Two paradigms
main
perform transaction
compute fees
if checking
then xxx
if savings
then xxx
etc.
compute interest
if checking
then xxx
if savings
then xxx
etc.
debitcredit
Account
credit
debit
SavingsAccount
compute interest
compute fees
CheckingAccount
compute interest
compute fees
© Gurbakash Phonsa Object Oriented concept review 4
Classes and Objects
• Object
• A chunk of structured data in a running software system
• Has properties
• Represent its state
• Has behaviour
• How it acts and reacts
• May simulate the behaviour of an object in the real world
© Gurbakash Phonsa Object Oriented concept review 5
Objects
© Gurbakash Phonsa Object Oriented concept review 6
Manit:
date of birth: 1990/03/03
position: Teller
Transaction 0487:
amount: 2200.00
time: 2011/09/01 14:30
MrGarg:
date of birth: 1980/01/01
address: 75 Object Dr.
Mortgage Account 209865:
balance: 198760.00
opened: 2015/08/15
property: 75 Object Dr.
Instant Teller 9876:
location: Java Valley Cafe
Savings Account 0012876:
balance: 19076.32
opened: 1997/03/03
Sandeep:
date of birth: 1985/02/02
position: Manager
address: 99 UML St.
address: 150 C++ Rd.
Classes
• A class:
• Is a unit of abstraction in an object oriented (OO) program
• Represents similar objects
• Its instances
• Is a kind of software module
• Describes its instances’ structure (properties)
• Contains methods to implement their behaviour
© Gurbakash Phonsa Object Oriented concept review 7
Naming classes
• Use capital letters
• e.g. BankAccount not bankAccount
• Use singular nouns
• Use the right level of generality
• e.g. Municipality, not City
• Make sure the name has only one meaning
• e.g. ‘bus’ has several meanings
© Gurbakash Phonsa Object Oriented concept review 8
Instance Variables
• Variables defined inside a class corresponding to data present in each
instance
i. Attributes
• Simple data
• e.g. name, dateOfBirth
ii. Associations
• Relationships to other important classes
• e.g. supervisor, coursesTaken
© Gurbakash Phonsa Object Oriented concept review 9
Variables vs. Objects
A variable
• Refers to an object
• May refer to different objects at different points in time
An object can be referred to by several different variables at the same
time
Type of a variable
• Determines what classes of objects it may contain
© Gurbakash Phonsa Object Oriented concept review 10
Class variables
• A class variable’s value is shared by all instances of a class.
• Also called a static variable
• If one instance sets the value of a class variable, then all the other
instances see the same changed value.
• Class variables are useful for:
• Default or ‘constant’ values (e.g. PI)
• Lookup tables and similar structures
Caution: do not over-use class variables
© Gurbakash Phonsa Object Oriented concept review 11
Methods, Operations and Polymorphism
Operation
• A higher-level procedural abstraction that specifies a type of behaviour
• Independent of any code which implements that behaviour
• E.g., calculating area (in general)
© Gurbakash Phonsa Object Oriented concept review 12
Methods, Operations and Polymorphism
• Method
• A procedural abstraction used to implement the behaviour of a class.
• Several different classes can have methods with the same name
• They implement the same abstract operation in ways suitable to each class
• E.g, calculating area in a rectangle is done differently from in a circle
© Gurbakash Phonsa Object Oriented concept review 13
Polymorphism
A property of object oriented software by which an abstract operation
may be performed in different ways in different classes.
• Requires that there be multiple methods of the same name
• The choice of which one to execute depends on the object that is in a variable
• Reduces the need for programmers to code many if-else or switch
statements
© Gurbakash Phonsa Object Oriented concept review 14
Organizing Classes into Inheritance Hierarchies
Superclasses
• Contain features common to a set of subclasses
Inheritance hierarchies
• Show the relationships among superclasses and subclasses
• A triangle shows a generalization
Inheritance
• The implicit possession by all subclasses of features defined in its
superclasses
© Gurbakash Phonsa Object Oriented concept review 15
Superclass
Subclass
Example Inheritance Hierarchy
Inheritance
• The implicit possession by all subclasses of features
defined in its superclasses
© Gurbakash Phonsa Object Oriented concept review 16
Account
MortgageAccountSavingsAccount ChequingAccount
The Isa Rule
Always check generalizations to ensure they obey the isa rule
• “A checking account is an account”
• “A village is a municipality”
Should ‘Province’ be a subclass of ‘Country’?
• No, it violates the isa rule
• “A province is a country” is invalid!
© Gurbakash Phonsa Object Oriented concept review 17
A possible inheritance hierarchy of mathematical objects
© Gurbakash Phonsa Object Oriented concept review 18
Rectangle
Quadrilate ralCircle
Ellipse Polygon PlaneLine
Shape3DShape2D
MatrixShape Point
MathematicalObject
Make Sure all Inherited Features Make Sense in Subclasses
© Gurbakash Phonsa Object Oriented concept review 19
Account
balance
opened
creditOrOverdraftLimit
credit
debit
calculateInterest
MortgageAccount
collateralProperty
collateralValue
setCollateralValue
ChequingAccount
highestChequeNumber
withdrawUsingCheque
calculateServiceCharge
SavingsAccount
Inheritance,
Polymorphism and
Variables
© Gurbakash Phonsa Object Oriented concept review 20
RegularPolygon
numPoints
radius
changeNumPoints
changeScale
getArea
getPerimeterLength
getVertices
Rectangle
height
width
setHeight
setWidth
changeScale
getArea
getPerimeterLength
getVertices
getBoundingRect
ArbitraryPolygon
points
addPoint
removePoint
rotate
changeScale
getArea
getPerimeterLength
getVertices
SimplePolygon
orientation
rotate
Shape2D
rotate
translate
changeScale
getArea
getPerimeterLength
getCenter
getBoundingRect
Ellipse
getSemiMajorAxis
getSemiMinorAxis
rotate
getArea
getPerimeterLength
getOrientation
getBoundingRect
Circle
rotate
getArea
getPerimeterLength
getBoundingRect
Polygon
getVertices
getBoundingRect
EllipticalShape
semiMajorAxis
semiMinorAxis
changeScale
changeScale
getRadius
getFocus1
getFocus2
orientation
getOrientation
center
UML Basics
Design Model
Process Model
Deployment Model
What Is the UML?
• The UML is a language for
• Visualizing
• Specifying
• Constructing
• Documenting
The artifacts of a software-intensive system.
• The Unified Modelling Language (UML) is an industry standard
for object oriented design notation, supported by the Object
Management Group (OMG).
The UML Is a Language for Visualizing
• Communicating conceptual models to others is prone
to error unless everyone involved speaks the same
language.
• There are things about a software system you can’t
understand unless you build models.
• An explicit model facilitates communication.
The UML Is a Language for Specifying
• The UML builds models that are precise, unambiguous,
and complete.
The UML Is a Language for
Constructing
• UML models can be directly connected to a variety of
programming languages.
• Maps to Java, C++, Visual Basic, and so on
• Tables in a RDBMS or persistent store in an OODBMS
• Permits forward engineering
• Permits reverse engineering
The UML Is a Language for Documenting
Use Case Diagram
Actor A
Use Case 1
Use Case 2
Use Case 3
Actor B
Class Diagram
GrpFile
read( )
open( )
create( )
fillFile( )
rep
Repository
name : char * = 0
readDoc( )
readFile( )
(from Persistence)
FileMgr
fetchDoc( )
sortByName( )
DocumentList
add( )
delete( )
Document
name : int
docid : int
numField : int
get( )
open( )
close( )
read( )
sortFileList( )
create( )
fillDocument( )
fList
1
FileList
add( )
delete( )
1
File
read( )
read() fill the
code..
Sequence Diagram
user
mainWnd fileMgr :
FileMgr
repositorydocument :
Document
gFile
1: Doc view request ( )
2: fetchDoc( )
3: create ( )
4: create ( )
5: readDoc ( )
6: fillDocument ( )
7: readFile ( )
8: fillFile ( )
9: sortByName ( )
ƯÁ¤¹®¼¿¡ ´ëÇÑ º¸±â¸¦
»ç¿ëÀÚ°¡ ¿äûÇÑ´Ù.
ÈÀϰü¸®ÀÚ´Â Àоî¿Â
¹®¼ÀÇ Á¤º¸¸¦ ÇØ´ç ¹®¼
°´Ã¼¿¡ ¼³Á¤À» ¿äûÇÑ´Ù.
È¸é °´Ã¼´Â ÀоîµéÀÎ
°´Ã¼µé¿¡ ´ëÇØ À̸§º°·Î
Á¤·ÄÀ» ½ÃÄÑ È¸é¿¡
º¸¿©ÁØ´Ù.
The UML addresses documentation of:
 System architecture
 Requirements
 System Testing
 Project planning and
 Release management
Deployment Diagram
Window95
¹®¼°ü¸®
Ŭ¶óÀ̾ðÆ®.EXE
Windows
NT
¹®¼°ü¸® ¿£Áø.EXE
Windows
NT
Windows95
Solaris
ÀÀ¿ë¼¹ö.EXE
Alpha
UNIX
IBM
Mainframe
µ¥ÀÌŸº£À̽º¼¹ö
Windows95
¹®¼°ü¸® ¾ÖÇø´
ºÐ»ê ȯ°æÀÇ Çϵå¿þ¾î¹× ³×Æ®¿÷À¸·ÎÀÇ Á¤º¸ ½Ã½ºÅÛ ¿¬°á ¸ðµ¨
- À©µµ¿ì 95 : Ŭ¶óÀ̾ðÆ®
- À©µµ¿ì NT: ÀÀ¿ë¼¹ö
- À¯´Ð½º ¸Ó½Å: ÀÀ¿ë ¼¹ö ¹× µ¥ÀÌŸ ¼¹ö, Åë½Å ¼¹ö
- IBM ¸ÞÀÎÇÁ·¹ÀÓ: µ¥ÀÌŸ ¼¹ö, Åë½Å ¼¹ö
History of the UML
UML 1.0
(Jan. ‘97)
UML 1.1
(Sept. ‘97)
UML 1.5
(March, ‘03)
UML 2.0
(2004)
Other
Methods
Booch ‘91 OMT - 1OOSE
Booch ’93 OMT - 2
Public
FeedbackUnified Method 0.8
(OOPSLA ’95)
UML 0.9
(June ‘96)
UML 0.91
(Oct. ‘96)
and
Diagrams
• Diagrams graphically depict a view of a part of your model.
• Different diagrams represent different views of the system
that you are developing.
• A model element will appear on one or more diagrams.
UML Diagrams in Software Architecture
Behavioral
Diagrams
Structural
DiagramsActivity
Diagrams
Sequence
Diagrams
Communication
Diagrams
State Machine
Diagrams
Deployment
Diagrams
Component
Diagrams
Composite
Structure
Diagrams
Class
Diagrams
Use-Case
Diagrams
Model
Key Diagrams in UML
Requirements
System Structure
System Behaviour
Use Case Diagrams
Interaction Diagrams
Activity Diagrams
State Charts
Class Diagrams
Collaboration Diagrams
Different diagrams of system for different people
Process View Deployment View
Logical View
Use-Case View
Implementation View
End-user
Functionality
Programmers
Software management
Performance, scalability, throughput
System integrators System topology, delivery,
installation, communication
System engineering
Analysts/Designers
Structure
UML Building Blocks
UML Building Blocks
© Gurbakash Phonsa Object Oriented concept review 32

Review of object orientation

  • 1.
    Review of ObjectOrientation
  • 2.
    What is ObjectOrientation? Procedural paradigm: • Software is organized around the notion of procedures • Procedural abstraction • Works as long as the data is simple • Adding data abstractions • Groups together the pieces of data that describe some entity • Helps reduce the system’s complexity. • Such as Records and structures Object oriented paradigm: • Organizing procedural abstractions in the context of data abstractions © Gurbakash Phonsa Object Oriented concept review 2
  • 3.
    Object Oriented paradigm Anapproach to the solution of problems in which all computations are performed in the context of objects. • The objects are instances of classes, which: • are data abstractions • contain procedural abstractions that operation on the objects • A running program can be seen as a collection of objects collaborating to perform a given task © Gurbakash Phonsa Object Oriented concept review 3
  • 4.
    A View ofthe Two paradigms main perform transaction compute fees if checking then xxx if savings then xxx etc. compute interest if checking then xxx if savings then xxx etc. debitcredit Account credit debit SavingsAccount compute interest compute fees CheckingAccount compute interest compute fees © Gurbakash Phonsa Object Oriented concept review 4
  • 5.
    Classes and Objects •Object • A chunk of structured data in a running software system • Has properties • Represent its state • Has behaviour • How it acts and reacts • May simulate the behaviour of an object in the real world © Gurbakash Phonsa Object Oriented concept review 5
  • 6.
    Objects © Gurbakash PhonsaObject Oriented concept review 6 Manit: date of birth: 1990/03/03 position: Teller Transaction 0487: amount: 2200.00 time: 2011/09/01 14:30 MrGarg: date of birth: 1980/01/01 address: 75 Object Dr. Mortgage Account 209865: balance: 198760.00 opened: 2015/08/15 property: 75 Object Dr. Instant Teller 9876: location: Java Valley Cafe Savings Account 0012876: balance: 19076.32 opened: 1997/03/03 Sandeep: date of birth: 1985/02/02 position: Manager address: 99 UML St. address: 150 C++ Rd.
  • 7.
    Classes • A class: •Is a unit of abstraction in an object oriented (OO) program • Represents similar objects • Its instances • Is a kind of software module • Describes its instances’ structure (properties) • Contains methods to implement their behaviour © Gurbakash Phonsa Object Oriented concept review 7
  • 8.
    Naming classes • Usecapital letters • e.g. BankAccount not bankAccount • Use singular nouns • Use the right level of generality • e.g. Municipality, not City • Make sure the name has only one meaning • e.g. ‘bus’ has several meanings © Gurbakash Phonsa Object Oriented concept review 8
  • 9.
    Instance Variables • Variablesdefined inside a class corresponding to data present in each instance i. Attributes • Simple data • e.g. name, dateOfBirth ii. Associations • Relationships to other important classes • e.g. supervisor, coursesTaken © Gurbakash Phonsa Object Oriented concept review 9
  • 10.
    Variables vs. Objects Avariable • Refers to an object • May refer to different objects at different points in time An object can be referred to by several different variables at the same time Type of a variable • Determines what classes of objects it may contain © Gurbakash Phonsa Object Oriented concept review 10
  • 11.
    Class variables • Aclass variable’s value is shared by all instances of a class. • Also called a static variable • If one instance sets the value of a class variable, then all the other instances see the same changed value. • Class variables are useful for: • Default or ‘constant’ values (e.g. PI) • Lookup tables and similar structures Caution: do not over-use class variables © Gurbakash Phonsa Object Oriented concept review 11
  • 12.
    Methods, Operations andPolymorphism Operation • A higher-level procedural abstraction that specifies a type of behaviour • Independent of any code which implements that behaviour • E.g., calculating area (in general) © Gurbakash Phonsa Object Oriented concept review 12
  • 13.
    Methods, Operations andPolymorphism • Method • A procedural abstraction used to implement the behaviour of a class. • Several different classes can have methods with the same name • They implement the same abstract operation in ways suitable to each class • E.g, calculating area in a rectangle is done differently from in a circle © Gurbakash Phonsa Object Oriented concept review 13
  • 14.
    Polymorphism A property ofobject oriented software by which an abstract operation may be performed in different ways in different classes. • Requires that there be multiple methods of the same name • The choice of which one to execute depends on the object that is in a variable • Reduces the need for programmers to code many if-else or switch statements © Gurbakash Phonsa Object Oriented concept review 14
  • 15.
    Organizing Classes intoInheritance Hierarchies Superclasses • Contain features common to a set of subclasses Inheritance hierarchies • Show the relationships among superclasses and subclasses • A triangle shows a generalization Inheritance • The implicit possession by all subclasses of features defined in its superclasses © Gurbakash Phonsa Object Oriented concept review 15 Superclass Subclass
  • 16.
    Example Inheritance Hierarchy Inheritance •The implicit possession by all subclasses of features defined in its superclasses © Gurbakash Phonsa Object Oriented concept review 16 Account MortgageAccountSavingsAccount ChequingAccount
  • 17.
    The Isa Rule Alwayscheck generalizations to ensure they obey the isa rule • “A checking account is an account” • “A village is a municipality” Should ‘Province’ be a subclass of ‘Country’? • No, it violates the isa rule • “A province is a country” is invalid! © Gurbakash Phonsa Object Oriented concept review 17
  • 18.
    A possible inheritancehierarchy of mathematical objects © Gurbakash Phonsa Object Oriented concept review 18 Rectangle Quadrilate ralCircle Ellipse Polygon PlaneLine Shape3DShape2D MatrixShape Point MathematicalObject
  • 19.
    Make Sure allInherited Features Make Sense in Subclasses © Gurbakash Phonsa Object Oriented concept review 19 Account balance opened creditOrOverdraftLimit credit debit calculateInterest MortgageAccount collateralProperty collateralValue setCollateralValue ChequingAccount highestChequeNumber withdrawUsingCheque calculateServiceCharge SavingsAccount
  • 20.
    Inheritance, Polymorphism and Variables © GurbakashPhonsa Object Oriented concept review 20 RegularPolygon numPoints radius changeNumPoints changeScale getArea getPerimeterLength getVertices Rectangle height width setHeight setWidth changeScale getArea getPerimeterLength getVertices getBoundingRect ArbitraryPolygon points addPoint removePoint rotate changeScale getArea getPerimeterLength getVertices SimplePolygon orientation rotate Shape2D rotate translate changeScale getArea getPerimeterLength getCenter getBoundingRect Ellipse getSemiMajorAxis getSemiMinorAxis rotate getArea getPerimeterLength getOrientation getBoundingRect Circle rotate getArea getPerimeterLength getBoundingRect Polygon getVertices getBoundingRect EllipticalShape semiMajorAxis semiMinorAxis changeScale changeScale getRadius getFocus1 getFocus2 orientation getOrientation center
  • 21.
    UML Basics Design Model ProcessModel Deployment Model
  • 22.
    What Is theUML? • The UML is a language for • Visualizing • Specifying • Constructing • Documenting The artifacts of a software-intensive system. • The Unified Modelling Language (UML) is an industry standard for object oriented design notation, supported by the Object Management Group (OMG).
  • 23.
    The UML Isa Language for Visualizing • Communicating conceptual models to others is prone to error unless everyone involved speaks the same language. • There are things about a software system you can’t understand unless you build models. • An explicit model facilitates communication.
  • 24.
    The UML Isa Language for Specifying • The UML builds models that are precise, unambiguous, and complete.
  • 25.
    The UML Isa Language for Constructing • UML models can be directly connected to a variety of programming languages. • Maps to Java, C++, Visual Basic, and so on • Tables in a RDBMS or persistent store in an OODBMS • Permits forward engineering • Permits reverse engineering
  • 26.
    The UML Isa Language for Documenting Use Case Diagram Actor A Use Case 1 Use Case 2 Use Case 3 Actor B Class Diagram GrpFile read( ) open( ) create( ) fillFile( ) rep Repository name : char * = 0 readDoc( ) readFile( ) (from Persistence) FileMgr fetchDoc( ) sortByName( ) DocumentList add( ) delete( ) Document name : int docid : int numField : int get( ) open( ) close( ) read( ) sortFileList( ) create( ) fillDocument( ) fList 1 FileList add( ) delete( ) 1 File read( ) read() fill the code.. Sequence Diagram user mainWnd fileMgr : FileMgr repositorydocument : Document gFile 1: Doc view request ( ) 2: fetchDoc( ) 3: create ( ) 4: create ( ) 5: readDoc ( ) 6: fillDocument ( ) 7: readFile ( ) 8: fillFile ( ) 9: sortByName ( ) ƯÁ¤¹®¼¿¡ ´ëÇÑ º¸±â¸¦ »ç¿ëÀÚ°¡ ¿äûÇÑ´Ù. ÈÀϰü¸®ÀÚ´Â Àоî¿Â ¹®¼ÀÇ Á¤º¸¸¦ ÇØ´ç ¹®¼ °´Ã¼¿¡ ¼³Á¤À» ¿äûÇÑ´Ù. È¸é °´Ã¼´Â ÀоîµéÀÎ °´Ã¼µé¿¡ ´ëÇØ À̸§º°·Î Á¤·ÄÀ» ½ÃÄÑ È¸é¿¡ º¸¿©ÁØ´Ù. The UML addresses documentation of:  System architecture  Requirements  System Testing  Project planning and  Release management Deployment Diagram Window95 ¹®¼°ü¸® Ŭ¶óÀ̾ðÆ®.EXE Windows NT ¹®¼°ü¸® ¿£Áø.EXE Windows NT Windows95 Solaris ÀÀ¿ë¼¹ö.EXE Alpha UNIX IBM Mainframe µ¥ÀÌŸº£À̽º¼¹ö Windows95 ¹®¼°ü¸® ¾ÖÇø´ ºÐ»ê ȯ°æÀÇ Çϵå¿þ¾î¹× ³×Æ®¿÷À¸·ÎÀÇ Á¤º¸ ½Ã½ºÅÛ ¿¬°á ¸ðµ¨ - À©µµ¿ì 95 : Ŭ¶óÀÌ¾ðÆ® - À©µµ¿ì NT: ÀÀ¿ë¼¹ö - À¯´Ð½º ¸Ó½Å: ÀÀ¿ë ¼¹ö ¹× µ¥ÀÌŸ ¼¹ö, Åë½Å ¼¹ö - IBM ¸ÞÀÎÇÁ·¹ÀÓ: µ¥ÀÌŸ ¼¹ö, Åë½Å ¼¹ö
  • 27.
    History of theUML UML 1.0 (Jan. ‘97) UML 1.1 (Sept. ‘97) UML 1.5 (March, ‘03) UML 2.0 (2004) Other Methods Booch ‘91 OMT - 1OOSE Booch ’93 OMT - 2 Public FeedbackUnified Method 0.8 (OOPSLA ’95) UML 0.9 (June ‘96) UML 0.91 (Oct. ‘96) and
  • 28.
    Diagrams • Diagrams graphicallydepict a view of a part of your model. • Different diagrams represent different views of the system that you are developing. • A model element will appear on one or more diagrams.
  • 29.
    UML Diagrams inSoftware Architecture Behavioral Diagrams Structural DiagramsActivity Diagrams Sequence Diagrams Communication Diagrams State Machine Diagrams Deployment Diagrams Component Diagrams Composite Structure Diagrams Class Diagrams Use-Case Diagrams Model
  • 30.
    Key Diagrams inUML Requirements System Structure System Behaviour Use Case Diagrams Interaction Diagrams Activity Diagrams State Charts Class Diagrams Collaboration Diagrams
  • 31.
    Different diagrams ofsystem for different people Process View Deployment View Logical View Use-Case View Implementation View End-user Functionality Programmers Software management Performance, scalability, throughput System integrators System topology, delivery, installation, communication System engineering Analysts/Designers Structure
  • 32.
    UML Building Blocks UMLBuilding Blocks © Gurbakash Phonsa Object Oriented concept review 32

Editor's Notes