12. Object oriented concept
An object-oriented programming (OOP) language makes use of the idea of classes and objects.
A program written in an object oriented language will be made up of a number of classes and objects. These classes and objects are manipulated through their internal methods.
Before OOP languages came along, procedural languages, such as 'C', treated data and the programming instructions that act upon the data as separate things.
This separation made it very easy to write faulty code such that one part of the software would over-write data at the wrong time.
A small non-OOP clip:
global variable X; function A() { X = 20; } function B() { X = 1000; } |
---|
In the clip above, one part of the main software may call function A to set the global variable X, but then another part of the software could call function B at the wrong time and X gets unintentionally changed. De-bugging this kind of problem can be difficult as the conditions that made it happen can be very obscure.
So the main idea of object oriented languages is to gather the data and all the methods (functions) that act upon that data into one entity called a 'class', so making data hiding, code re-use and maintenance much easier.
Pro
- OOP makes it easier to provide working code. A class can be fully tested and released to other coders in the team to use
- Classes can be treated as 'black boxes'. Coder do not need to know how the class works internally. They just need to know how to manipulate it through its methods.
- There are many 'design patterns' available, developed over the years, that solve common programming tasks. A coder can pick up a design pattern for perhaps an user interface and begin coding straight away.
- Code re-use. Easy to move a class from one application and re-use it on another project
Con
- Steep learning curve, becoming proficient in an object-oriented language can take a long time as it is more complicated than a standard procedural language.
- Complex - it needs skill to craft efficient and flexible classes.
Challenge see if you can find out one extra fact on this topic that we haven't already told you
Click on this link: OOP languages
Copyright © www.teach-ict.com