1 / 21

Object, Class, Message & Methods

Object, Class, Message & Methods. OOP. Objects. 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.

morrison
Download Presentation

Object, Class, Message & Methods

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object, Class, Message & Methods OOP

  2. Objects • 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.

  3. Object Structure Benjamin as an object: attributes: name=“Benjamin” address=“1, Robinson road” budget=“2000” methods: purchase() {send a purchase request} getBudget() {return budget}

  4. Object Structure Bernie as an object: attributes: name=“Bernie” address=“18, Sophia road” budget=“1000” methods: purchase() {send a purchase request} getBudget() {return budget}

  5. Class • 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().

  6. Class Class Customer: attributes: name address budget methods: purchase() {send a purchase request} getBudget() {return budget}

  7. Object vs class • 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).

  8. Object & Class • Examine :Object & Class at salesperson

  9. Object Structure Sean as an object: attributes: name=“Sean” methods: takeOrder() { check with the warehouse on stock abailability check with the warehouse on delivery schedule if ok then{instruct warehouse to deliver stock(address, date) return ok else return not ok}

  10. Class Class Salesperson: attributes: name methods: takeOrder() { check with the warehouse on stock abailability check with the warehouse on delivery schedule if ok then{instruct warehouse to deliver stock(address, date) return ok else return not ok}

  11. Message & Method • 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.

  12. Message Components • 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

  13. Message components 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} Sean is receiver of the message takeOrder is method call on Sean Reds are arguments of message

  14. Method • 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.

  15. Object Structure Sean as an object: attributes: name=“Sean” methods: takeOrder(who,stock,address,date) { check with the warehouse on stock abailability check with the warehouse on delivery schedule if ok then{instruct warehouse to deliver stock to address on date return ok else return not ok}

  16. Creating Objects • Objects are created from classess. • Created object instances are individuals with their own state. • Ex: Counter

  17. First Object First Counter Object Attributes: number = 10 Methods: add() {number = number + 1} initialize() {number = 0} getNumber() {return number}

  18. Second Object SecondCounter Object Attributes: number = 2 Methods: add() {number = number + 1} initialize() {number = 0} getNumber() {return number}

  19. Third Objek ThirdCounter Object Attributes: number = 7 Methods: add() {number = number + 1} initialize() {number = 0} getNumber() {return number}

  20. Class Counter Class Counter Attributes: number Methods: add() {number = number + 1} initialize() {number = 0} getNumber() {return number}

  21. Summary • 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).

More Related