CSE 1201 Object Oriented Programming Object Oriented Design.
Object Oriented Programming A new way of thinking.
-
Upload
monica-norton -
Category
Documents
-
view
234 -
download
3
Transcript of Object Oriented Programming A new way of thinking.
![Page 1: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/1.jpg)
Object Oriented Programming
A new way of thinking
![Page 2: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/2.jpg)
Programming Methodologies
• Two approaches to programming design:– Procedural• Fortran, assembly, C
– Object-oriented• C++, Java, Python
![Page 3: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/3.jpg)
Procedural Programming
• Focus is on algorithm: – Program is built by combining algorithms– Data is just what algorithms work on
• Issues?
![Page 4: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/4.jpg)
Procedural Programming
• Issues?– Organization – Modularity
![Page 5: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/5.jpg)
Objects
• Objects : Code entities uniting data and behavior
![Page 6: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/6.jpg)
Objects
• Objects : Code entities uniting data and behavior
• Object Oriented Programming (OOP): Program consists of interacting objects
![Page 7: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/7.jpg)
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
![Page 8: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/8.jpg)
Real World Objects
Objects A pen A computer keyboard A shoe A mouse
![Page 9: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/9.jpg)
Real World Objects
Objects Non-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
![Page 10: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/10.jpg)
Real World Objects
Objects Non-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
![Page 11: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/11.jpg)
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
![Page 12: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/12.jpg)
Ex: Circle
• State : – Radius– X of center?– Y of center?
• Behaviors : – getArea()
![Page 13: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/13.jpg)
Procedural Version
• Circles represented as double:
• Functions to operate on circles:
![Page 14: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/14.jpg)
Procedural Version
• Circles represented as struct:
• Functions to operate on circle struct:
![Page 15: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/15.jpg)
Classes
• Classes are blueprints for objects– Define the basic form
![Page 16: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/16.jpg)
C++ Classes
• class keyword defines a new type
• Defines members – Variables – Functions
![Page 17: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/17.jpg)
Instantiation
• Individual objects are instantiated from the class description:
Class Name: Circle Data Fields:
radius is _______ Functions:
getArea
Circle Object 1 Data Fields:
radius is 10
Circle Object 2 Data Fields:
radius is 25
Circle Object 3 Data Fields:
radius is 125
A class template
Three objects of the Circle class
![Page 18: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/18.jpg)
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
![Page 19: Object Oriented Programming A new way of thinking.](https://reader035.fdocuments.in/reader035/viewer/2022062221/56649f515503460f94c74afb/html5/thumbnails/19.jpg)
Writing Behaviors
• Object's properties available in member functions
c1.getArea()getArea uses c1's radius
c2.getArea()getArea uses c2's radius