oop. object attribute definition allows for object to have independent attribute values. ex:...
TRANSCRIPT
![Page 1: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/1.jpg)
Object, Class, Message & Methods
OOP
![Page 2: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/2.jpg)
Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some similar information like a name, an address, & a budget.
Beside attribute, object also have some method. Ex: Benjamin & Bernie as customers have some behaviour like making purchase.
Objects
![Page 3: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/3.jpg)
Benjamin as an object:attributes:
name=“Benjamin”address=“1, Robinson road”budget=“2000”
methods:purchase() {send a purchase
request}getBudget() {return budget}
Object Structure
![Page 4: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/4.jpg)
Bernie as an object:attributes:
name=“Bernie”address=“18, Sophia road”budget=“1000”
methods:purchase() {send a purchase
request}getBudget() {return budget}
Object Structure
![Page 5: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/5.jpg)
A Class is a definition template for structuring and creating objects with the same attributes and methods.
Ex: Like Benjamin & Bernie, All customers of HomeCare share the same set of attribute & method definition. They all have attributes: name, address & budget, and methods purchase() & getBudget().
Class
![Page 6: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/6.jpg)
Class Customer:attributes:
nameaddressbudget
methods:purchase() {send a purchase
request}getBudget() {return budget}
Class
![Page 7: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/7.jpg)
One major difference between object & class is in the way are treated in objects & class.
A Class attributes & methods are declarations that do not contain values.
An Object are created instances of a class that has it own attributes & methods (state).
Object vs class
![Page 8: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/8.jpg)
Examine : Object & Class at salesperson
Object & Class
![Page 9: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/9.jpg)
Sean as an object:attributes:
name=“Sean”methods:
takeOrder() {check with the warehouse on stock
abailabilitycheck with the warehouse on delivery
scheduleif ok then{instruct warehouse to deliver
stock(address, date) return okelse return not ok}
Object Structure
![Page 10: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/10.jpg)
Class Salesperson:attributes:
namemethods:
takeOrder() {check with the warehouse on stock
abailabilitycheck with the warehouse on delivery
scheduleif ok then{instruct warehouse to deliver
stock(address, date) return okelse return not ok}
Class
![Page 11: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/11.jpg)
Objects communicate with one another by sending messages.
A messages is a method call from a message-sending object (sender) to a message-receiving object (receiver).
An object responds to message by executing one of its methods.
Such parameter allows for added flexibility in message passing.
Offcourse, an object may have as many methods as required.
Message & Method
![Page 12: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/12.jpg)
A message composed of:◦ An object identifier. ◦ A method name.◦ arguments (parameter).
Ex: Benjamin sent a messages to Sean when Benjamin wanted to buy a sofa set. The reasonable location is in Benjamin’s purchase() method
Message Components
![Page 13: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/13.jpg)
Benjamin as an object:attributes:
name=“Benjamin”address=“1, Robinson road”budget=“2000”
methods:purchase(
Sean.takeOrder(“Benjamin”, “Sofa”,”1, Robinson Road”, “12 September 2012”)
getBudget() {return budget}
Message components
Sean is receiver of the message takeOrder is
method call on Sean
Reds are arguments of
message
![Page 14: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/14.jpg)
A message is valid if the receiver has a method that corresponds to the method named in message & the appropriate arguments.
Ex: the takeOrder() message is valid because Sean has a corresponing method & the required arguments.
Method
![Page 15: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/15.jpg)
Sean as an object:attributes:name=“Sean”methods:takeOrder(who,stock,address,date) {check with the warehouse on stock abailabilitycheck with the warehouse on delivery scheduleif ok then{instruct warehouse to deliver stock to address on date return okelse return not ok}
Object Structure
![Page 16: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/16.jpg)
Objects are created from classess. Created object instances are individuals
with their own state. Ex: Counter
Creating Objects
![Page 17: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/17.jpg)
First Counter ObjectAttributes:
number = 10Methods:
add() {number = number + 1}initialize() {number = 0}getNumber() {return number}
First Object
![Page 18: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/18.jpg)
Second Counter ObjectAttributes:
number = 2Methods:
add() {number = number + 1}initialize() {number = 0}getNumber() {return number}
Second Object
![Page 19: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/19.jpg)
Third Counter ObjectAttributes:
number = 7Methods:
add() {number = number + 1}initialize() {number = 0}getNumber() {return number}
Third Objek
![Page 20: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/20.jpg)
Class CounterAttributes:
numberMethods:
add() {number = number + 1}initialize() {number = 0}getNumber() {return number}
Class Counter
![Page 21: OOP. Object attribute definition allows for object to have independent attribute values. Ex: Benjamin & Bernie are customers of HomeCare share some](https://reader036.vdocuments.mx/reader036/viewer/2022070404/56649f345503460f94c51185/html5/thumbnails/21.jpg)
Objects are defined by classes. Objects from the same class share the same definition of
attributes and methods. Objects from the same class may not have the same attribute
values. Objects from different classes do not share the same definition of
attributes or methods. Objects created from the same class share the same definition of
attributes and methods but their state may differ. A method is a set of operations executed by an object upon the
receipt of a message. A message has three components: an object identifier, a method
name and arguments. A message-receiving object is a server(receiver)to a message-
sending object known as a client(sender).
Summary