What defines the behavior of an object in object-oriented programming ?

In order to continue enjoying our site, we ask that you confirm your identity as a human. Thank you very much for your cooperation.

We now have now added object-oriented terminology in our arsenal of definitions. We defined objects as instances of classes, where it is an object of its own set of data and behaviors.

What are these data and behaviors associated with each object?

1.Data describes objects Data represents roughly the individual characteristics of an object. The class of an object defines a specific characteristics that are shared by all instances of the defined class. On the other hand, each instances would have different data values for each shared characteristics. For example, the length of the tail of a dog of the following classes are of different values:

What defines the behavior of an object in object-oriented programming ?

We can say that the class of dogs have a tail length attribute. Note, however that attribute doesn't necessarily have to be unique. For example, twins can have the same genetic code, but they are different instances of a single class - human.

Attributes are frequently referred to as properties. Some authors suggest that the two terms have different meanings:

  • attributes are settable
  • properties are read only

Fruit Inventory Application
We may want to know what orchard the orange came from, when it was picked, and how much it weights. We may also want to keep track of where each basket is stored. We might also have color attribute for our fruits (e.g. apple), and barrels might come in different sizes.

Depending on how detailed our design needs to be, we can also specify the type for each attribute.

  • they are often primitive data types: integer, floating-point, string, byte or boolean
  • they can also represent data structures: lists, trees, graphs or other classes

This is one area where the design stage can overlap with the programming stage. Most of the times we don't have to worry with this at the design stage, as implementation-specific details are chosen during the programming stage.

2.Behaviors are actions Behaviors are actions that occur on an object. A behavior that can be applied to a specific class of objects is called a method. In programming, method are like functions, but it has access to all the data associated with that objects.

Like functions, methods can accept parameters and return values.

Numbers is a simple example of an object. With methods that includes the arithmetic operations addition and multiplication.

  1. parameters are a list of objects that need to be passed into the method that is being called. For our add method, we could have the following parameters, x and y:
    What defines the behavior of an object in object-oriented programming ?
  2. return values are the the result of the method
    What defines the behavior of an object in object-oriented programming ?

    if we invoke the method to values x=1, y=2 then the returned value is z = 3

Fruit Inventory Application

An action that can be associated with oranges in our application is the pick action. Pick would place the orange in a basket by updating the basket attribute on the orange, and by adding the orange to the oranges list on the Basket.

What defines the behavior of an object in object-oriented programming ?

Basket can have a sell action. When a basket is sold, our inventory system might update some data on as-yet unspecified objects for accounting and profit calculations.

We can also add a discard method in case our basket of oranges might go bad.

Adding models and methods to individual objects allows us to create a system of interacting objects.

  • Each object in the system is a member of a certain class
  • These classes specify what types of data the object can hold and what methods can be invoked on it.

Object-oriented analysis and design is all about figuring out what those objects are and how they should interact.


Disclaimer: this is a summary of section 1.3 from the book "Python 3 - Object Oriented Programming: Dusty Phillips", the content apart from rephrasing is identical, most of the equations are from the book and the same examples are treated. All of the equation images were screenshot from generated latex form.

Thank you for reading ...
What defines the behavior of an object in object-oriented programming ?

What defines the behavior of an object in object-oriented programming ?

What defines the behavior of an object in object-oriented programming ?

#python #education #books #object-oriented

Get full access to Hands-On Object-Oriented Programming with Kotlin and 60K+ other titles, with free 10-day trial of O'Reilly.

There's also live online events, interactive content, certification prep materials, and more.

Every class contains attributes and behaviors. Attributes are the characteristics of the class that help to distinguish it from other classes. Behaviors are the tasks that an object performs. A person's attributes, for example, include their age, name, and height, while their behaviors include the fact that a person can speak, run, walk, and eat. In Kotlin, attributes are called properties and behaviors are called functions. Properties are presented with different data types, and behaviors are described using functions. When we map a Person class in Kotlin, it may look as shown in the following class diagram:

What defines the behavior of an object in object-oriented programming ?

The properties ...

Get Hands-On Object-Oriented Programming with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.

Get Mark Richards’s Software Architecture Patterns ebook to better understand how to design components—and how they should interact.

It’s yours, free.

Get it now

What defines the behavior of an object in object-oriented programming ?