Ad Code

Difference in attribute and behavior?

What is difference between attribute and behavior


Attribute is the characteristic while behavior is the performed operations.

Attributes:
An object’s data is defined by its attributes, or pieces of data that describe aspects of the object. For example, an attribute of an Employee object might be called “phone_number,” which might contain a series of characters that represent the employee’s phone number. Other attributes of an Employee object might be “first_name,” “last_name”, and “job_title,” all of which give additional, detailed information about each Employee.

It may help to think of the set of attributes belonging to an object as a sort of “mini-database” that contains information representing the “real-world thing” that the object is attempting to describe. The complete collection of attributes assigned to an object defines that object’s state. When one or more of an object’s attributes are modified, the object is said to have changed its state.

Methods or Behavior:
The set of actions that an object may perform is defined by its methods. Methods are code definitions attached to an object that perform actions based on the object’s attributes. For example, a method of an Employee object named “getFirstName” may return the value of the object’s “first_name” attribute, while a method of an Employee object named “setFirstName” might change the value of the object’s “first_name” attribute. The “getTitle” method of an Employee object may return a value of “Vice President” or “Janitor, depending on which Employee object is being queried.

Methods are similar to functions in procedural languages like ‘C’. The key difference between a method and a function is that a method is “bound” to, or attached to, an object: instead of operating solely on “external” data that is passed to it via arguments, it may also operate on the attributes of the object to which it is bound.
Reactions

Post a Comment

0 Comments