Introduction to OOP - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Introduction to OOP

Description:

A variable of a given Class type My Ferrari. Objects are distinct from each other. Different variables - My Ferrari vs. Bob's Ferrari. Fundamental OOP Concepts ... – PowerPoint PPT presentation

Number of Views:506
Avg rating:3.0/5.0
Slides: 18
Provided by: steven85
Category:

less

Transcript and Presenter's Notes

Title: Introduction to OOP


1
Introduction to OOP
  • Fundamental OOP Concepts
  • Advantages of OOP
  • Data Types
  • Classes
  • Objects
  • Encapsulation
  • Message Passing
  • Inheritance
  • Polymorphism

2
Fundamental OOP Concepts
  • World is Full of Things or Objects
  • Everything is an object - specific
    characteristics, attributes, behavior
  • People, places, things i.e. a Car
  • Objects are the Things in OOP
  • Objects have parts called Members
  • Attributes (Data) - seats, doors, engine
  • Methods (Functions) - start, accelerate
  • Objects belong to a Class
  • A variable of a given Class type My Ferrari
  • Objects are distinct from each other
  • Different variables - My Ferrari vs. Bobs
    Ferrari

3
Fundamental OOP Concepts
  • Objects Fall into Classes
  • Based on overall characteristics and behavior
  • Define many different Objects that are similar
  • Identify the component parts of Objects
  • Distinguish the differences between Objects

4
Advantages of OOP
  • Increased Productivity
  • Machine Code-Assembler-Procedural-Object
    Oriented
  • Greater Abstraction, less dependent on machine
  • Enhanced Reliability
  • self-contained objects
  • easier to debug
  • Improved Maintenance
  • localization of responsibility
  • reduced global data
  • Reuseable Code
  • Clearly defined interfaces
  • Extendable through Inheritance

5
Programming Methodologies
Procedural Programming
Object-Oriented Programming
Functional Abstraction Structured Programming
Support Global Data Structures Separate
Functions Function parameters Main Program uses
Sub-functions Tight data coupling Functional
Thinking - What functions do I need to
solve the problem?
Object (Type) Abstraction Structured Programming
Support Objects have Data Structures Objects
have Functions (Methods) Objects called with
messages Objects use helper methods Loose data
coupling Object Thinking - What objects are
in the problem domain?
6
Object-Oriented Activities
  • Object-Oriented Analysis - OOA
  • Identify objects in the real world problem
    domain
  • Specify responsibilities and interactions
  • Organize into Classes
  • Object-Oriented Design - OOD
  • Specify messages and expected behavior
  • Objects used as building blocks
  • Object-Oriented Programming - OOP
  • Classes built per design
  • Objects created to handle Message Transactions
  • Test Classes and Objects individually
  • Main Program defines Objects and Hooks them
    Together

7
What is a Data Type?
  • Fundamental programming elements
  • Built-in types int, char, float, etc
  • Have specific form
  • Memory size, organization
  • Have specific behavior
  • Valid operations - / , etc
  • Different behavior depending upon the type
  • User specified collections of Data Types
  • Structures, Arrays, Records

8
Classes
  • User Defined Data Types
  • Defines Basic Characteristics of an Object
  • Allow New Programming Elements
  • Extends language
  • Have Attributes and Methods
  • Contain Data for the Object state
  • Provide functions unique to the kind of Object
  • Abstract Data Types (ADT) - A Generalized Class
  • Defines Basic Features of a Class
  • Cannot create Objects of an ADT Class
  • ADT is a partial class used to create a
    Complete Class
  • i.e. Vehicle ADT must be made into a Car,
    Truck, Motorcycle

9
Encapsulation
  • Information hiding
  • Data values are private
  • Some functions may be private
  • Internal details not visible outside
  • Data representation is hidden
  • Like a Black-Box
  • An object has a specified set of functions that
    it performs
  • Each function may alter/control internal data of
    object
  • User of object doesnt care how it works
  • Keeps information consistent
  • External functions cant directly alter internal
    state
  • Object has ultimate control over what happens

10
Objects
  • Class Variables are Objects
  • Object is a part of of the program
  • Class declares the properties of an object
  • OOP - Object is an instance of a class
  • Multiple objects can be made from each class
  • Objects can be contained within other objects
  • or, within data structures
  • Objects usually have both Data and Functions
  • Perform action on the objects data
  • Objects Data State
  • Persists with objects lifespan
  • Available to all methods of the object

11
Class and Object
Object Usage //Create an Object Circle
MyCircle // Call Methods MyCircle.Locate (40,
25) MyCircle.Size (16.5) MyCircle.Draw
() MyCircle.Erase ()
A Circle Class
12
Message Passing
  • Communication between objects
  • Objects receive and respond to messages
  • Objects may send messages to other objects
  • Information (Data) flow
  • Messages usually contain information parameters
  • Objects perform operation on its own data
  • Objects return information as needed
  • Defined interface to outside world
  • Messages are how we tell an object to do
    something
  • Method (Function) invocation
  • What an object knows or does is important
  • How an object works is hidden (black-box)
  • Circle object example

13
A Circle Drawing Class
Circle ------------------------- int X, Y float
radius ------------------------- Draw Erase Locate
(int x, int y) Size (float radius) Move (int x,
int y)
Name of Class Attributes Messages (aka Methods
or Functions)
14
Inheritance
  • Real world
  • Natural process
  • Parents - Children
  • Same kind of a thing, but different
  • Is-a Relationship vs. Has-a Relationship
  • OOP
  • Generalized class into a specialized class
  • Families of Classes
  • Code sharing
  • Alter behavior and/or information
  • Single and multiple inheritance

15
Inherited Class
Circle ------------------------- int X, Y float
radius ------------------------- Draw Erase Locate
(int x, int y) Size (float radius) Move (int x,
int y)
ColorCircle Circle --------------------------- i
nt color --------------------------- setColor
(int color) Draw () Erase ()
Inherited from Circle Added Attribute Added /
modified messages
Inheritance
16
Polymorphism
  • Many Forms
  • Meaning of Method is consistent
  • Easier to use, reduces the name game
  • Families of functions
  • Overloading
  • Different types, same operations
  • Different functions, same name
  • Object Polymorphism
  • Different Objects, same message
  • Dynamic behavior
  • Run-time binding

Creatures
17
Summary
  • Objects exist in real world
  • Humans naturally tend to categorize objects into
    classes
  • OOP is based on user defined classes and objects
  • Objects are variables of a class type
  • Encapsulation promotes safe programming
  • Messages passed for behavior and information
    transfer
  • Inheritance allows classes to be based on other
    classes
  • Polymorphism allows different object types to
    respond to the same message
Write a Comment
User Comments (0)
About PowerShow.com