Skip to main content
added 1 character in body
Source Link
Thomas Junk
  • 9.6k
  • 2
  • 26
  • 47

Does an object have to represent an entity?

Question: Which entity does a Logger represent?

Not metaphorically - literally.

When explaining OOP to students it is helpful to explain objects with analogies to the physical world.

Alan Kay - one of the fathers of OOP - wrote the following:

[...]

The original conception of it had the following parts.

  • I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages
  • I wanted to get rid of data.

[...]

OOP to me means only messaging, local retention and protection and

hiding of state-process, and extreme late-binding of all things.

almost unbelievable HW architecture. I realized that the

cell/whole-computer metaphor would get rid of data

source

From this, objects are best understood as

  • autarkic objects encapsulating / hiding data

  • communicating with other objects via messages

Can classes represent entity-less objects?

Definitely: Think of Math


Regarding your example:

Example: can a class be called MotorOperations or MotorActions, where there is no entity, but methods inside the class do things like

  • getMotorDataFromHTMLForm()
  • getMotorManufacturers()
  • selectMotorFromUserRequirements($requirements)
  • canMotorCanHandleOperatingConditions($conditions)
  • computePowerConsumptionForMotor($id)

To decide, where to put these methods, you have to take a look at responsibilities: who is respnsible for what.

getMotorDataFromHTMLForm()

The context of such a method would be constructing a motor-object. It is not the responsibility of the motor to create itself from Data retrieved via a form. There are at least two objects involved; one is the motor and the other is the creator of the motor.

getMotorManufacturers()

The typical context in which one would write such a method is a service.

selectMotorFromUserRequirements($requirements)

This would also be used in a service-context

canMotorCanHandleOperatingConditions($conditions)

This is a question to a motor-object

computePowerConsumptionForMotor($id)

This too is a question besbest asked a motor itself.


tl;dr

The metaphor of objects as physically objects is more irritating than helpful.

Does an object have to represent an entity?

Question: Which entity does a Logger represent?

Not metaphorically - literally.

When explaining OOP to students it is helpful to explain objects with analogies to the physical world.

Alan Kay - one of the fathers of OOP - wrote the following:

[...]

The original conception of it had the following parts.

  • I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages
  • I wanted to get rid of data.

[...]

OOP to me means only messaging, local retention and protection and

hiding of state-process, and extreme late-binding of all things.

almost unbelievable HW architecture. I realized that the

cell/whole-computer metaphor would get rid of data

source

From this, objects are best understood as

  • autarkic objects encapsulating / hiding data

  • communicating with other objects via messages

Can classes represent entity-less objects?

Definitely: Think of Math


Regarding your example:

Example: can a class be called MotorOperations or MotorActions, where there is no entity, but methods inside the class do things like

  • getMotorDataFromHTMLForm()
  • getMotorManufacturers()
  • selectMotorFromUserRequirements($requirements)
  • canMotorCanHandleOperatingConditions($conditions)
  • computePowerConsumptionForMotor($id)

To decide, where to put these methods, you have to take a look at responsibilities: who is respnsible for what.

getMotorDataFromHTMLForm()

The context of such a method would be constructing a motor-object. It is not the responsibility of the motor to create itself from Data retrieved via a form. There are at least two objects involved; one is the motor and the other is the creator of the motor.

getMotorManufacturers()

The typical context in which one would write such a method is a service.

selectMotorFromUserRequirements($requirements)

This would also be used in a service-context

canMotorCanHandleOperatingConditions($conditions)

This is a question to a motor-object

computePowerConsumptionForMotor($id)

This too is a question bes asked a motor itself.


tl;dr

The metaphor of objects as physically objects is more irritating than helpful.

Does an object have to represent an entity?

Question: Which entity does a Logger represent?

Not metaphorically - literally.

When explaining OOP to students it is helpful to explain objects with analogies to the physical world.

Alan Kay - one of the fathers of OOP - wrote the following:

[...]

The original conception of it had the following parts.

  • I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages
  • I wanted to get rid of data.

[...]

OOP to me means only messaging, local retention and protection and

hiding of state-process, and extreme late-binding of all things.

almost unbelievable HW architecture. I realized that the

cell/whole-computer metaphor would get rid of data

source

From this, objects are best understood as

  • autarkic objects encapsulating / hiding data

  • communicating with other objects via messages

Can classes represent entity-less objects?

Definitely: Think of Math


Regarding your example:

Example: can a class be called MotorOperations or MotorActions, where there is no entity, but methods inside the class do things like

  • getMotorDataFromHTMLForm()
  • getMotorManufacturers()
  • selectMotorFromUserRequirements($requirements)
  • canMotorCanHandleOperatingConditions($conditions)
  • computePowerConsumptionForMotor($id)

To decide, where to put these methods, you have to take a look at responsibilities: who is respnsible for what.

getMotorDataFromHTMLForm()

The context of such a method would be constructing a motor-object. It is not the responsibility of the motor to create itself from Data retrieved via a form. There are at least two objects involved; one is the motor and the other is the creator of the motor.

getMotorManufacturers()

The typical context in which one would write such a method is a service.

selectMotorFromUserRequirements($requirements)

This would also be used in a service-context

canMotorCanHandleOperatingConditions($conditions)

This is a question to a motor-object

computePowerConsumptionForMotor($id)

This too is a question best asked a motor itself.


tl;dr

The metaphor of objects as physically objects is more irritating than helpful.

Source Link
Thomas Junk
  • 9.6k
  • 2
  • 26
  • 47

Does an object have to represent an entity?

Question: Which entity does a Logger represent?

Not metaphorically - literally.

When explaining OOP to students it is helpful to explain objects with analogies to the physical world.

Alan Kay - one of the fathers of OOP - wrote the following:

[...]

The original conception of it had the following parts.

  • I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages
  • I wanted to get rid of data.

[...]

OOP to me means only messaging, local retention and protection and

hiding of state-process, and extreme late-binding of all things.

almost unbelievable HW architecture. I realized that the

cell/whole-computer metaphor would get rid of data

source

From this, objects are best understood as

  • autarkic objects encapsulating / hiding data

  • communicating with other objects via messages

Can classes represent entity-less objects?

Definitely: Think of Math


Regarding your example:

Example: can a class be called MotorOperations or MotorActions, where there is no entity, but methods inside the class do things like

  • getMotorDataFromHTMLForm()
  • getMotorManufacturers()
  • selectMotorFromUserRequirements($requirements)
  • canMotorCanHandleOperatingConditions($conditions)
  • computePowerConsumptionForMotor($id)

To decide, where to put these methods, you have to take a look at responsibilities: who is respnsible for what.

getMotorDataFromHTMLForm()

The context of such a method would be constructing a motor-object. It is not the responsibility of the motor to create itself from Data retrieved via a form. There are at least two objects involved; one is the motor and the other is the creator of the motor.

getMotorManufacturers()

The typical context in which one would write such a method is a service.

selectMotorFromUserRequirements($requirements)

This would also be used in a service-context

canMotorCanHandleOperatingConditions($conditions)

This is a question to a motor-object

computePowerConsumptionForMotor($id)

This too is a question bes asked a motor itself.


tl;dr

The metaphor of objects as physically objects is more irritating than helpful.