IS 8020 - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

IS 8020

Description:

Navigability. Can you get from an instance of class A to an associated instance of class B? Part of reducing coupling is being specific about navigability. Dynamic ... – PowerPoint PPT presentation

Number of Views:12
Avg rating:3.0/5.0
Slides: 53
Provided by: bense7
Category:

less

Transcript and Presenter's Notes

Title: IS 8020


1
IS 8020
  • Spring 2004
  • Object Oriented Modelling

2
Views Of Objects and Classes
  • In computer
  • Representation of state
  • Implementation of behaviors
  • Real World
  • Interpret the meanings

3
Real World Objects
  • Objects are distinctly identifiable
  • We classify objects by grouping them according to
    common characteristics

4
Building Models
  • In our model, objects are software entities
  • Objects have these characteristics
  • State
  • Behavior
  • Identity
  • All the objects in a class share some
    characteristics of behavior and/or state

5
Representation of State
  • State is represented by attributes or fields
  • Each field represents some aspect of the state of
    the object

6
Representation of Behavior
  • Behaviors are implemented by methods
  • aka operations
  • aka functions
  • Behaviors are implemented by code that may access
    and change the state of the object

7
Characteristics of Fields
  • Fields have
  • Name
  • Type
  • Value
  • The type indicates the kinds of values that the
    field may take

8
Characteristics of Methods
  • Methods have
  • Name
  • Type
  • Value
  • Type type is interpreted as the kind of data the
    method returns
  • The values is the code that carries out any
    activities of the method

9
Features
  • The features of an object are its methods and
    attributes
  • Or, its behavior and state

10
Identity
  • Two ways of comparing if objects are the same
  • Equals
  • Equals means that objects have the same state
  • had 24 sons and she named them all Dave
  • Identity
  • Identity means that the objects are actually the
    same object

11
Mutators and Accessors
  • Object fields are mutable, that is, changeable
  • Mutator methods actually change the fields
  • Accessor methods do not change the fields

12
Immutable Objects
  • Some objects have no behaviors that alter the
    state
  • These objects are called immutable

13
Building Models
  • The activity of OO modeling involves defining
    classes
  • Classes specify templates or definitions
    according to which objects can be created
  • The act of creating an object from a class is
    called instantiation
  • An object is called an instance of a class

14
Class Point
  • Fields
  • Named x and y
  • Both type int
  • Values assigned later (why?)
  • Method
  • Named move
  • Its type is void, no value returned
  • The implementation will be shown later

15
Parameters
  • Methods may require extra data to carry out their
    operation
  • The extra data is specified using parameters
  • Parameters each have a specified type

16
Diagrams
  • We are visual animals
  • Diagrams are useful tools
  • UML Unified Modeling Language
  • Rectangles with three sub-parts represent classes

17
UML Class
18
Specification of Fields
  • visibility name type
  • Other possibilities are described in the text

19
Visibility
20
What Does Visibility Mean
  • Who can access what features?
  • Private restricts access to the class
  • Public allows access to all
  • Package allows access from the same package
    (defined later)
  • Protected allows access by subclasses (defined
    later)

21
Class Point
22
Objects in UML
  • These are less common
  • Modeling usually focuses on describing classes
    rather than individual objects

23
Passing a Message
  • A method is invoked or called to activate it
  • The syntax is
  • object.methodName(parameters)
  • For example
  • p1.move(10, 20)

24
Packages
  • Packages are groups of related classes
  • The relationship may be somewhat informal
  • The Java library is organized into a large number
    of packages
  • The Java library uses a hierarchical naming
    convention
  • We probably will not create packages, just use
    them

25
OO Design Principles
  • Modularity
  • Abstraction
  • Encapsulation
  • Polymorphism

26
Modularity
  • Decomposing a system into component parts
  • The decomposition should exhibit
  • High cohesion
  • Low coupling

27
Cohesion
  • The parts of a module should be related
  • A module that makes deposits to bank accounts and
    graphs stock-market activity is not cohesive
  • This is a criterion sometimes applied to a class
    when critiquing a design
  • Example A patent for a combination fly-trap and
    cheese grater

28
Coupling
  • Coupling refers to interdependence of modules
  • High coupling can lead to problems when changing
    a system
  • Changes will propagate more widely in highly
    coupled systems

29
Abstraction
  • In this context, means that a module is
    characterized by a service contract
  • The services that the module are characterized
  • Including the conditions that have to be met
    a-priori
  • The methods by which the service are provided are
    not part of the contract

30
Examples
  • Telephones
  • Telephone system is very complex
  • The interface is much less complex
  • sqrt(x)
  • This gives us the square root
  • We dont need to understand how it works

31
Encapsulation
  • Interface is separate from implementation and
    representation
  • Information hiding The user only sees whats
    needed to be able to use the services

32
Employee Example
  • Attributes must be stored somewhere
  • Might be in working memory
  • Might be in a database
  • Methods carry out some task
  • Methods may simply operate on local data
  • Methods may send requests to other systems to
    carry out the activity

33
Polymorphism
  • Different providers may honor the same interface

34
Class Activity
  • Design a Bank Account
  • Determine attributes of the account
  • Identify type
  • Determine methods of the account
  • Identify parameters
  • Identify return

35
Follow-up
  • Consider issues of cohesion
  • Should customer be represented?

36
Class Relationships
  • Inheritance
  • Association
  • Aggregation and Composition
  • Dependency

37
Interfaces
  • Interfaces are like classes in that they support
    a contract for behavior
  • However, interfaces do not actually implement any
    of that behavior

38
Inheritance
  • Formally, one class inherits from another if all
    the objects from the first class are also in the
    second class
  • We will usually say that the first class extends
    the second class
  • A class implements an interface
  • An interface extends another interface
  • This is all Java jargon

39
Inheritance Conceptually
  • If one class inherits from another, we say that
    the first class is-a the second class
  • We can substitute an element of the sub-class for
    an element of the super-class

40
Student Example
  • Relationships among groups
  • Draw diagram

41
Levels of Abstraction
  • Higher levels of abstraction are more general
  • Lower levels are more specific
  • Super-classes are more general
  • A super-class may be so general that no
    implementation makes sense, thus, an interface
  • Sub-classes are more specific

42
Multiple Inheritance
  • Conceptually, a class may inherit from a number
    of other classes
  • Java does not support multiple inheritance

43
Associations
  • Binary relationships between classes
  • The two classes play roles in the relation
  • Names
  • Role names
  • Association name

44
Multiplicities
  • How many of a class will participate in a
    relation?
  • Many students will be advisee to a faculty member
  • Each student will have one advisee

45
Specifying Multiplicities
  • i
  • l..u
  • Examples
  • 0..
  • 1..
  • 1

46
Aggregation and Composition
  • Has-a relation
  • Component/Aggregate
  • Composition implies ownership and linking of
    lifetimes

47
Dependency
  • Uses relation

48
Navigability
  • Can you get from an instance of class A to an
    associated instance of class B?
  • Part of reducing coupling is being specific about
    navigability

49
Dynamic Behavior
  • Sequence Diagram
  • Read through diagram on page 37
  • Read through state diagrams
  • Theyll be less useful for us

50
Use Cases
  • Actors
  • Those who carry out actions
  • Usually people
  • May be other computers
  • Use Cases
  • Very high level actions of the total system
  • Very undetailed

51
E-Bookstore
  • Create part of the use-case diagram
  • Create an activity diagram
  • Scenarios and activity diagram

52
Identifying Objects
  • Objects are often nouns
  • Attributes are often adjectives
  • Behaviors are often verbs
Write a Comment
User Comments (0)
About PowerShow.com