Introducing the Class - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Introducing the Class

Description:

Example - car. Car dealer views a car from selling features standpoint ... Example - car radio. Interface consists of controls. and power and antenna connectors ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 19
Provided by: lyon
Category:

less

Transcript and Presenter's Notes

Title: Introducing the Class


1
Chapter 11
  • Introducing the Class

2
Software Engineering Goals
  • Reliability
  • Understandability
  • Cost Effectiveness
  • Adaptability
  • Reusability
  • Reliability
  • An unreliable life-critical system can be fatal
  • Understandability
  • Future development is difficult if software is
    hard to understand
  • Cost Effectiveness
  • Cost to develop and maintain should not exceed
    profit
  • Adaptability
  • System that is adaptive is easier to alter and
    expand
  • Reusability
  • Improves reliability, maintainability, and
    profitability

3
Software Engineering Principles
  • Abstraction
  • Extract the relevant properties while ignoring
    inessentials
  • Encapsulation
  • Hide and protect essential information through a
    controlled interface
  • Modularity
  • Hierarchy
  • Abstraction
  • Extract the relevant properties while ignoring
    inessentials
  • Encapsulation
  • Hide and protect essential information through a
    controlled interface
  • Modularity
  • Dividing an object into smaller modules so that
    it is easier to understand and manipulate
  • Hierarchy
  • Abstraction
  • Extract the relevant properties while ignoring
    inessentials
  • Encapsulation
  • Hide and protect essential information through a
    controlled interface
  • Modularity
  • Dividing an object into smaller modules so that
    it is easier to understand and manipulate
  • Hierarchy
  • Ranking or ordering of objects based on some
    relationship between them
  • Abstraction
  • Encapsulation
  • Modularity
  • Hierarchy
  • Abstraction
  • Extract the relevant properties while ignoring
    inessentials
  • Encapsulation
  • Modularity
  • Hierarchy

4
Abstraction
  • Extract the relevant object properties while
    ignoring inessentials
  • Defines a view of the object
  • Example - car
  • Car dealer views a car from selling features
    standpoint
  • Price, length of warranty, color,
  • Mechanic views a car from systems maintenance
    standpoint
  • Size of the oil filter, type of spark plugs,

5
Encapsulation
  • Steps
  • Decompose an object into parts
  • Hide and protect essential information
  • Supply interface that allows information to be
    modified in a controlled and useful manner
  • Internal representation can be changed without
    affecting other system parts
  • Example - car radio
  • Interface consists of controlsand power and
    antenna connectors
  • The details of how it works is hidden
  • To install and use a radio
  • Do not need to know anything about the radios
    electronics

6
Modularity
  • Dividing an object into smaller pieces or modules
    so that the object is easier to understand and
    manipulate
  • Most complex systems are modular
  • Example - Automobile can be decomposed into
    subsystems
  • Cooling system
  • Radiator Thermostat Water pump
  • Ignition system
  • Battery Starter Spark plugs

7
Hierarchy
  • Hierarchy
  • Ranking or ordering of objects based on some
    relationship between them
  • Help us understand complex systems
  • Example - a company hierarchy helps employees
    understand the company and their positions within
    it
  • For complex systems, a useful way of ordering
    similar abstractions is a taxonomy from least
    general to most general

8
OO Design and Programming
  • Object-oriented design and programming
    methodology supports good software engineering
  • Promotes thinking in a way that models the way we
    think and interact with the real world
  • Example - watching television
  • The remote is a physical object withproperties
  • Weight, size, can send messageto the television
  • The television is also a physical objectwith
    various properties

9
Objects
  • An object is almost anything with the following
    characteristics
  • Name
  • Properties
  • The ability to act upon receiving a message
  • Basic message types
  • Directive to perform an action
  • Request to change one of its properties

10
Class Construct
  • Defining objects with attributes and behavior

11
Class Types
  • Class construct
  • Allows programmers to define new data types for
    representing information
  • Class type objects can have both attribute
    components and behavior components
  • Provides the object-oriented programming in C
  • Class construct
  • Allows programmers to define new data types for
    representing information
  • Class type objects can have both attribute
    components and behavior components
  • Provides the object-oriented programming in C
  • Example we shall consider is
  • Class queue

12
Queue Definition
  • class queue
  • int q100
  • int sloc, rloc
  • public
  • void init()
  • void qput(int I)
  • void qget()
  • // init(), qput(), and qget() are member
    functions
  • // q, sloc, and rloc are private but member
  • // functions have access to them

13
Queue Definition (continued)
  • //Initialize the queue
  • void queueinit()
  • rloc sloc 0
  • //Put an integer into the queue.
  • void queueqput(int i)
  • if (sloc 100)
  • cout ltlt "Queue is full.\n"
  • return
  • sloc
  • qsloc i

14
Queue Definition (continued)
  • //Get an integer from the queue.
  • int queueqget()
  • if (rloc sloc)
  • cout ltlt "Queue underflow.\n"
  • return 0
  • rloc
  • return qrloc

15
Use of the Queue
  • int main()
  • queue a, b //create two queue objects
  • a.init()
  • b.init()
  • a.qput(10)
  • b.qput(19)
  • a.qput(20)
  • b.qput(1)
  • cout ltlt "contents of queue a " ltlt a.qget() ltlt
    endl
  • cout ltlt "contents of queue a " ltlt a.qget() ltlt
    endl
  • cout ltlt "contents of queue b " ltlt b.qget() ltlt
    endl
  • cout ltlt "contents of queue b " ltlt b.qget() ltlt
    endl
  • return 0

16
FIFO Structure(First In, First Out)
  • a.qput(10)
  • a.qput(20)

10
20
10
20
10
17
FIFO Structure(First In, First Out)
  • a.qget()
  • a.qget()

10
20
10
20
20
18
LIFO Structure(Last In, First Out)
  • Stack
  • s.add(5) top() //returns 6
  • s.add(6) top() //returns 5

1
6
5
Write a Comment
User Comments (0)
About PowerShow.com