Object-oriented programming is concerned with constructing computer systems out of interacting units of software, called objects. Objects know nothing of how other objects work, but they can interact (when a program is executing) by sending messages to each other and they may get replies back, called message answers, from other objects. One of the most powerful aspects of object-oriented programming is that the code that produces interacting objects can be reused and interchanged between programs, so increasing programming productivity. In other words, in the object-oriented approach to software design all the processing carried out by software is considered as being done by objects. Software objects are used to model real-life ones. The software objects simulate the part of the real world (often called the application domain or problem domain) with which we are concerned.
For example, if we need a system to help manage patients in a hospital (the domain), our software will, in some sense, have to construct representations of part of the world of hospital administration. the objects we might need are those that deal with modelling real-world patients, doctors, nurses, wards and so on. Since the system would be a computerised one we would also need objects for the user interface, such as windows, menus and buttons.
Programming in an object-oriented language requires more than just learning the syntax rules: it requires thinking in terms of the objects that will carry out the required tasks. rather than in terms of data structures and algorithms, as might be the case in a non-object-oriented context.
Two important aspects of an object are its attributes and its behaviour. An attribute is some external property or characteristics of an object, so a patient object might have attributes such as condition, date admitted, medication and so on. The attribute value of ‘condition’ might be ‘malaria’ and the attribute value of ‘date admitted’ might be ‘3/1/2021’. Attributes describe the kind of information that can be determined about an object. The state of an object is the particular data held by all the attributes at a given time; that is the attribute values.
Each object has a set of messages it understands. The action an object performs in response to a particular message is an example of behaviour. Behaviour is the collection of actions an object might carry out in response to all the messages it understands. An object modelling a patient might need to know how to behave in response to messages such as ‘take medicine’. The message ‘take medicine’ might well be sent by a nurse object.
When an object sends a message to another object, all it needs to know is what behaviour will result – importantly, it does not need to know how the internal structure of the object receiving the message produces the behaviour.
The only way of getting an object to do something is to send it a message. Similarly, to find out the value of an attribute, a message must be sent to the object. On receipt of a message it understands, the object will perform some action such as changing the value of one of its attributes or returning some information. Sometimes the requested action may involve the object sending messages to other objects.
Although as users of a software system we cannot interact directly with software objects, we can communicate with them via a user interface. Actions such as clicking the mouse, or pressing a key on the keyboard, will cause messages to be sent to the appropriate objects.
One benefit of the object-oriented approach is that, because an object is responsible for updating its own data, any changes to the structure of that data affect only that type of object. Since it is usual for software to be changed and adapted after it has been built, this is an important benefit.
Another important benefit is reusability.