Object Oriented Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Object Oriented Programming

Description:

Object Oriented Programming ... 010101 1110101 10101 Object Oriented Data and operations are grouped together WombatWorld Data Encapsulation class Wombat ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 17
Provided by: TalP4
Learn more at: https://www.cs.unca.edu
Category:

less

Transcript and Presenter's Notes

Title: Object Oriented Programming


1
Object Oriented Programming
2
Mapping the world to software
  • Objects in the problem domain are mapped to
    objects in software

3
Object Oriented
  • Data and operations are grouped together

WombatWorld
4
Data Encapsulation
class Wombat private int direction
private int leavesEaten public Wombat()
public move()
5
Advantages of Encapsulation
  • Protection
  • Consistency
  • Allows change

6
Objects and Classes
  • Classes reflect concepts, objects reflect
    instances that embody those concepts.

object
class
woman
Not Fred
7
Objects and Classes contd
Operations MakeDesposit Transfer WithDraw GetBalan
ce
Class BankAccount Balance InterestYTD Owner Accoun
t_number
Balance500 InterestYTD 10 Owner
Mark Account_number 12345
Balance 10,000 InterestYTD 25 Owner
Martha Account_number 76543
8
Objects as instances of Classes
  • The world conceptually consists of objects
  • Many objects can be said to be of the same type
    or class
  • My bank account, your bank account, Bill Gates
    bank account
  • We call the object type a class

9
Instantiation
  • An Object is instantiated from a Class

BankAccount myAccount myAccount new
BankAccount()
10
Objects and Classes
  • Class
  • A template for objects
  • Visible in source code
  • Object
  • Own copy of data
  • Active in running program
  • Occupies memory
  • Has the set of operations (i.e., functions)
    defined in the class

11
Classification
12
Inheritance
  • A class which is a subtype of a more general
    class is said to be inherited from it.
  • The sub-class inherits the base class data
    members and member functions

13
Inheritance contd
  • A sub-class has all the data members of its
    base-class plus those that it declares
  • A sub-class has all member functions of its base
    class (with changes) plus those that it defines
  • More on this later.

14
What is a good class ?
  • A class abstracts real-world objects
  • A class should be non-trivial in the context of
    the program (it has data and operations different
    from other classes)

15
Class Design
  • Use is a or has a to determine whether
    something should be a subclass or be a data item.
  • Ex
  • A dog has a name. Not A dog is a name.
  • A dog is a mammal. Not A dog has a mammal.
    (unless its in predator-mode which isnt a step
    in oo design).

16
Summary
  • What is Object Oriented Programming?
  • Object-oriented programming is a method of
    implementation in which programs are organized as
    collections of objects, each of which represents
    an instance of some class, and whose classes are
    all members of one or more hierarchy of classes
    united via inheritance relationships
Write a Comment
User Comments (0)
About PowerShow.com