Much of the power and flexibility of modern software analysis and design derives from its use of objects.
The use of objects allows designers to create programs that are more easily maintained and extended. And it makes it easier to design very complex or large-scale programs.
Procedural programming represents the world as a series of processes acting on data.
After use cases and problem statements have been created, you need to model how the problem domain actually behaves.
So creating objects is usually the next stage in a design project after use cases or problem statements have been drawn up.
It has clear boundaries. And it has a well-defined behavior and a definite purpose.
But objects are created only when a program runs. In contrast to classes, they exist at a definite point in time.
Classes create an abstract representation of the world, letting you discard unnecessary details.
- relationships to other objects
Different problem domains have different requirements, even when they contain the same objects. You will need to create specific classes that suit the needs of each problem domain.
- bank teller
So a class named ComputerSystem will capture the essential features of ATMs, computers, and the bank mainframe.
You can create a class to model the behavior of bank tellers, customers, and managers. And all of these things will be instances of the ComputerSystemUser class.
For example, a car that could never be moved would not be a typical car.
So you can alter the state of an object by changing the value of its attributes.
Sometimes they act on other objects, or even on themselves. And sometimes they are acted on by other objects.
This protects a program against malicious damage. And it prevents data being accidentally deleted or overwritten by other parts of the computer program.
Together, the visible operations and attributes of a class make up its interface. This is the part of a class that is acted on by operations from other classes or system users.
- A modifier operation alters the state of an object.
- A selector operation lets you access the state of an object without changing it.
- An iterator operation allows all the parts of an object to be accessed in a definite order. Object-oriented programmers often create a separate class that is responsible for using the iterator function on an object.
- The constructor operation creates an object and fixes its initial state.
- The destructor operation destroys an object.
For example, an object in the bank's Employee class could be involved with the payroll system, with the customer database, or with the command hierarchy.
So you can capture all the meaningful functionality of an object by specifying its state and behavior.
Even objects with the same properties and behavior have their own individual identity. For instance, two blue station wagons that were built in the same year by the same manufacturer are still separate and unique cars.
You can, for example, respray your car or fit another engine, and it will still be the same car.
Objects represent particular instances of things, and classes represent types of object. Different classes are used for different problem domains.
States are the conditions in which objects exist. An object's state is defined by its attributes. An object's attributes are usually static, and the values of the attributes are usually dynamic.
The term "behavior" refers to how objects interact with each other, and it is defined by the operations an object can perform. There are five kinds of operations: modifiers, selectors, iterators, constructors, and destructors. No matter what its attributes and operations are, an object is always uniquely itself. It retains its identity regardless of changes to its state or behavior.