Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Programming A new way of thinking.

Similar presentations


Presentation on theme: "Object Oriented Programming A new way of thinking."— Presentation transcript:

1 Object Oriented Programming A new way of thinking

2 Programming Methodologies Two approaches to programming design: – Procedural Fortran, assembly, C – Object-oriented C++, Java, Python

3 Procedural Programming Focus is on algorithm: – Program is built by combining algorithms – Data is just what algorithms work on Issues?

4 Procedural Programming Issues? – Organization – Modularity

5 Objects Objects : Code entities uniting data and behavior

6 Objects Objects : Code entities uniting data and behavior Object Oriented Programming (OOP): Program consists of interacting objects

7 Objects Objects : Code entities uniting data and behavior Object Oriented Programming (OOP): Program consists of interacting objects Object-oriented design (OOD): – Identify objects – Determine how objects need to interact

8 Real World Objects Objects A pen A computer keyboard A shoe A mouse

9 Real World Objects ObjectsNon-objects A pen The upper 37% of the pen A computer keyboard The air above the keyboard A shoe The color of the shoe A mouse The sound of a mouse click

10 Real World Objects ObjectsNon-objects A pen The upper 37% of the pen A computer keyboard The air above the keyboard A shoe The color of the shoe A mouse The sound of a mouse click An object holds together as a single whole An object has properties An object can do things and can have things done to it

11 Code Objects Model real world objects & conceptual entities 3 Key Things: – state : it has various properties (data) – behavior : things it can do things and that can be done to it – identity : each object is a distinct individual

12 Ex: Circle State : – Radius – X of center? – Y of center? Behaviors : – getArea()

13 Procedural Version Circles represented as double: Functions to operate on circles:

14 Procedural Version Circles represented as struct: Functions to operate on circle struct:

15 Classes Classes are blueprints for objects – Define the basic form

16 C++ Classes class keyword defines a new type Defines members – Variables – Functions

17 Instantiation Individual objects are instantiated from the class description:

18 Using Classes Class is data type Variable stores object. operator accesses members Each object has own state c1 radius: 10 c2 radius: 25 c3 radius: 125

19 Writing Behaviors Object's properties available in member functions c1.getArea() getArea uses c1's radius c2.getArea() getArea uses c2's radius


Download ppt "Object Oriented Programming A new way of thinking."

Similar presentations


Ads by Google