Object oriented programming
From DocForge
Object-oriented programming, or OOP, is a style of software development characterized by having complex data types called objects which encapsulate state, data, and functionality. They are typically defined by classes or prototypes and later instantiated for use during program execution.
A core concept of object oriented programming is that data can often be modeled after real-world objects. Any object in the real world has a set of characteristics which define it and a set of actions which can be done to it. By programmatically defining these in a somewhat analogous way to the real world, software developers can logically organize code and software can better model the real world.
Contents |
[edit] Uses
[edit] Common Object Characteristics
- Properties represent data stored within an object. Properties usually represent characteristics of the object. For example, an object representing a car might have color and weight properties. Properties are typically variables defined within a class. Strongly typed languages enforce typing of properties in the same way they enforce typing of variables.
- Methods are functions which may act on data stored within an object.
- Accessor methods are used to retrieve data from an object. Accessor methods are sometimes used when public properties aren't made available. They allow other code to alter and view the data stored in an object.
[edit] Scope
Many languages, such as C++ and PHP 5, support some form of scope (or visibility) which determines what code may execute a method or evaluate a property. In other languages, such as Python, every aspect of an object is always public.
- Public properties and methods can be accesssed by code written outside of a class definition.
- Private properties and methods can not be accesssed by code written outside of a class definition.
- Protected properties and methods can only be accessed within the class defining them and in any other classes which inherit them.
[edit] Languages Supporting Object-Oriented Programming
Languages vary in their support of objects. Java, for example, requires object-oriented development. In PHP, Perl and Python objects are completely optional.