Академический Документы
Профессиональный Документы
Культура Документы
UVLE
UVLE Course: GmE205-GTH-19201
enrolment key: gme205-0sz0h2
What is Object Oriented Programming?
According Alan Kay (smalltalk and OOP):
Everything Is An Object.
Objects communicate by sending and receiving messages (in terms of objects).
Objects have their own memory (in terms of objects).
Every object is an instance of a class (which must be an object).
The class holds the shared behavior for its instances (in the form of objects in a
program list)
Being Object Oriented
MENTAL EXERCISE:
Recognizing Objects from Nouns
Imagine you want to measure the area and perimeter of squares, rectangles, circles, and ellipses.
Being Object Oriented
MENTAL EXERCISE:
Recognizing Objects from Nouns
Create function to calculate the areas.
Advantage: straightforward
Disadvantage: does not represent real world object
Create software objects that represent the state and behavior of a square, rectangle, circle, and an
ellipse
Being Object Oriented
MENTAL EXERCISE:
Recognizing Objects from Nouns
Data required for each shape:
Square Length of side
Rectangle Width and height
Circle Radius (usually labeled as r)
Ellipse Semi-major axis (usually labeled as a) and semi-minor axis (usually labeled as b)
Make a blueprint to simplify the process of drawing each rectangle with their different widths and
heights.
Being Object Oriented
MENTAL EXERCISE:
Generating blueprints for objects
A class is a blueprint or a template definition from which the objects are created.
Classes are models that define the state and behavior of an object.
Objects are also known as instances
Being Object Oriented
MENTAL EXERCISE:
Recognizing attributes/fields
With the Square class, it is necessary to know the length of side for each instance of this class, that
is, for each square object.
Thus, we need an encapsulated variable that allows each instance of this class to specify the value
of the length of side.