What is Object Oriented Programming?
We will take a very brief look at object oriented programming. There are many good books available on the subject for those who want an in-depth cover of the topic. Here, we will just introduce a few key ideas and define some of the terms used.
Many of the things we use every day are built from a set of re-usable components. Cars, televisions, and computers are all designed this way. This makes them cheaper to manufacture, and easier to maintain, since a faulty component can just be replaced. Object oriented programming is an attempt to use the same method to design and write computer systems
Key Terms in OOP
Some key terms used in Object Oriented Programming (OOP)
Class | A blueprint or design from which an object, or component, is built. You can think of this as being like the mould in which a steering wheel for a car is made. |
Object | An actual component. This is like an actual steering wheel, built from the mould. There may be several steering wheels made from the same mould. Each one may be different in some respects. For example, one may be painted black while another is painted silver. |
Properties | These are things that describe an individual object. For example, the steering wheel in the above example could have the property color. One object will have a color of black; another a color of silver. |
Methods | These are actions that can be carried out by an object, and are defined in the class. The steering wheel could have a method named turn, since this is something that it can do. |
Inheritance | OOP allows for sub classes to be defined. A subclass inherits all the properties and methods of the original class, and can add a few of its own. A steering wheel that can lock could be a sub class of steering wheel. It has all of the original properties and methods, such as color and turn, and adds in new methods called lock and OOP allows for sub classes to be defined. A subclass inherits all the properties and methods of the original class, and can add a few of its own. A steering wheel that can lock could be a sub class of steering wheel. It has all of the original properties and methods, such as color and turn, and adds in new methods called lock and unlock.. |
Encapsulation | When fitting a component such as a power supply into a computer, it's not neccessary to know how it works or what goes on inside it. All you need to know is what type of connections it has, and what voltage should be supplied to it. Powers supplies are interchangeable provided that the connections and power requirements are the same. Encapsulation means that objects in a computer system should behave the same way. They can only communicate with other objects using predefined connections, and should be interchangeable with other objects using the same connections |
All of these ideas will become clearer as we see them in practice in later chapters.