Modeling in Problem Solving - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

Modeling in Problem Solving

Description:

... objects, such as persons, animals, cars, balls, traffic lights, and so on ... An objects is a dynamic concept because. Objects exhibit independent behavior ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 42
Provided by: csis5
Category:

less

Transcript and Presenter's Notes

Title: Modeling in Problem Solving


1
Modeling in Problem Solving
  • A real-world problem consists of several
    collections of entities interacting with one
    another and with their surroundings.
  • When solving a real-world problem, a simplified
    representation of the problem is used to study
    the problem and construct a solution.
  • This representation is called a model of the
    problem.

2
Modeling in Problem Solving
  • In developing object-oriented applications, one
    of the main goals is to construct abstract
    representations in software of some aspect of the
    real world.
  • An abstract representation is a simplified
    description with only the relevant or essential
    characteristics of part of a real system.

3
Models with Objects
  • A model is composed of objects, each one
    representing a real-world entity. The model
    includes descriptions about these objects and
    their interactions.
  • Objects are the central focus of the
    object-oriented approach to problem solving.
  • A model is an abstract description of some part
    of the problem domain. The task of designing and
    constructing a model is called modeling.

4
Objects and Modeling
  • Objects are given the responsibility of carrying
    out specific tasks of the solution.
  • Objects are models of the real-world entities
    identified in the real-world environment of the
    problem.
  • Objects with similar characteristics are grouped
    into collections, also known as classes.

5
Object-Oriented Modeling
6
Object Modeling
  • Within the boundaries of the problem, three basic
    issues in modeling are
  • Identifying the objects to include in the model
  • Describing these objects
  • Grouping similar objects into collections

7
Describing Objects
  • Real-world entities or objects are the
    fundamental components of a real world system.
  • Recall that objects are abstract representations
    of real-world entities

8
Types of Objects
  • Physical objects, which are tangible objects,
    such as persons, animals, cars, balls, traffic
    lights, and so on
  • Nontangible objects, which are not directly
    visible, such as contracts, accounts, and so on
  • Conceptual objects, which do not clearly exist
    but are used to represent part of the components
    or part of the behavior of the problem. For
    example, the environment that surrounds the
    problem and that affects the entities of the
    problem

9
Objects as Dynamic Entities
  • An objects is a dynamic concept because
  • Objects exhibit independent behavior
  • Objects interact with one another.

10
Objects Interact
  • Objects communicate by sending messages to each
    other
  • Objects collaborate for a common goal.

11
General Characteristics of Objects
  • State, represented by the set of properties (or
    attributes) and their associated values
  • Behavior, represented by the operations, also
    known as methods, of the object
  • Identity, which is a property that can help
    identify an object

12
Objects
  • Objects are dynamic entities
  • They exhibit behavior
  • They change state
  • They interact with other objects

13
Objects and Classes
  • Every object belongs to a class.
  • Classes are used to define the properties and
    behavior of similar objects.

14
A Simple Example of an Object
  • An object of class Ball. Its identity identifies
    an object of class Ball.
  • The attributes of this object are color, size,
    and move_status.
  • The figure shows the UML diagram for two Ball
    objects and illustrates their structure.

15
Object Diagram
  • An object diagram is basically a rectangle
    divided into three sections.
  • The top section indicates the class of the object
  • The middle section includes the list of the
    attributes and their current values
  • The bottom section includes the list of
    operations in the object.

16
Two Object Diagrams
17
Another Example of an Object
  • An object of class Person is shown in the next
    figure.
  • This object has only two attributes, name and age
  • The object has two operations, play and stop.
    The values of these attributes are also shown.

18
Behavior of Class Person
  • The behavior of this object is simple the object
    can
  • start playing (with operation play)
  • stop playing (with operation stop).

19
Object of class Person
20
Object Services
  • An object provides one or more services
  • Each service is defined by one of the operations
    in the object
  • Other objects can request a service

21
Object Interaction
  • Objects interact by sending messages to each
    other.
  • A message represents a request for service, which
    is provided by the object receiving the message.

22
Client and Supplier Objects
  • The sender object is known as the client of a
    service
  • The receiver object is known as the supplier of
    the service.

23
Message Sending
  • The purpose of sending a message is the request
    for some operation of the receiver object to be
    carried out in other words, the request is a
    call to one of the operations of the supplier
    object.
  • Objects carry out operations in response to
    messages.
  • A message is always sent to a specific object.
    This is also known as method invocation.

24
Message Description
  • A message contains four parts
  • The object owner of the function being called
  • The operation to be invoked or started, which is
    the service requested and must be an accessible
    operation
  • The input data required by the operation to
    perform, which is known as the arguments
  • The output data, which is the reply to the
    message and is the actual result of the request

25
Describing Object Interaction
  • To describe the general interaction between two
    or more objects (the sending of messages between
    objects), a UML diagram known as a Collaboration
    Diagram is used to describe the interaction.
  • The next figure describes an example using this
    type of UML diagram.

26
Example of Object Interaction
  • To describe the interaction among an object of
    class Person with the two objects of class Ball,
    a simple collaboration diagram is drawn.
  • The next figure shows a collaboration diagram
    with these three objects.
  • The Person object invokes the move operation of
    the Ball object by sending a message to the first
    Ball object, and as a result of this message,
    that object (of class Ball) performs its move
    operation.

27
UML Collaboration Diagram
28
Information Hiding
  • Based on the idea of abstraction
  • Objects present an
  • Internal view.
  • External view.

29
Internal View
  • A list of all the operations in the object
  • This includes the operations in the external view
    and the internal operations only started by the
    object itself
  • The internal operations cannot be started by
    other objects.

30
External View
  • This view is a list of all the services in an
    object that can be requested by other objects
  • This is basically a list of the operations that
    can be started from outside the object
  • This list is defined in the class

31
Encapsulation
  • Integration of the data (attributes) of an object
    with the behavior definitions (methods) in a
    single unit.
  • A protection mechanism
  • It involves information hiding

32
Classes
  • Defines a collection of similar objects
  • A class is described by the attributes and
    operations of the objects that belong to the
    class.

33
Classes (2)
  • Classes are static entities, they only exists in
    the program before execution time.
  • Classes are the principal decomposition units of
    programs.

34
Programs
  • There are two views for a program
  • Static view -- a program is an assembly of
    classes (static view)
  • Dynamic view -- a program in execution consists
    of a group of objects interacting among
    themselves.

35
Programs and Classes
  • An object-oriented program consists of one or
    more classes
  • One of these classes has the main control in
    executing the program

36
Category of OO Programs
  • In Java and KJP there are three kinds of
    programs
  • Console applications
  • Graphics applications
  • Applets

37
Program with Four Classes
38
Visibility of a Class
  • Visibility is defined by the external view of the
    objects of the class
  • All the features in the external view are said to
    be public

39
Visibility of a Class (2)
  • The features of an object that are accessible
    from other objects are public
  • The private features of an object are not
    accessible from other objects

40
General Structure of a Class
41
General Structure of a Function
Write a Comment
User Comments (0)
About PowerShow.com