Object-oriented programming: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric Evers
imported>Eric Evers
Line 26: Line 26:
Multiple inheritance languages
Multiple inheritance languages
  C++, python, Ruby, perl, Eiffel
  C++, python, Ruby, perl, Eiffel
Class inheritance is often described with a Class Diagram.
Example Class Diagram
+------------+
| Object    |    class name
+------------+
| id        |    attribute variable
+------------+
| get id    |    member functions
| set id    |
+------------+
    / \
      |
      |
+---------------+
| part          |    class name
+---------------+
| container_obj |    attribute variable
+---------------+
| get container |    member functions
| set container |
+---------------+
    / \
      |
      |
+------------+
| container  |    class name
+------------+
| parts      |    attribute variable
+------------+
| get parts  |    member functions
| set parts  |
+------------+
In this class diagram, each container is a part, and each part is an object. Because of inheritance, each container with include a
container_obj and an id number inherited from their ancestors.

Revision as of 13:21, 16 October 2008

Object oriented programming

Overview

Object oriented programming is a technique to organize data and functions in a computer program. Specifically, data structures called objects are instantiated(created) from templates called classes. Attributes(member variables) and methods(member functions) are hidden inside of objects. Sometimes the attributes and methods are private and available only inside a class. Othertimes some attributes and methods are public and available to other classes or objects.

Object oriented programming languages

Some programming languages have object oriented structures build into them. Many languages can create object structures from scratch if needed. C++ has objects built in to it. One can program using objects with pure C, but only if you build your own objects from scratch. Some languages are pure object languages and strictly require that all code be an OOP(object oriented program).

Strict OOP languages include

Java, C#, Ruby and Eiffel

Some languages have OOP as an option and are not strict.

python, perl and C++

Geos was an object oriented OS written in assembler from stratch.

Inheritance

Child classes inherit attributes and methods from their parent classes. Some languages only allow one parent, these languages are single inheritance languages. This compares to others that are multiple inheritance languages.

Single inheritance languages

java, C#

Multiple inheritance languages

C++, python, Ruby, perl, Eiffel

Class inheritance is often described with a Class Diagram.

Example Class Diagram
+------------+
| Object     |    class name
+------------+
| id         |    attribute variable
+------------+
| get id     |    member functions
| set id     |
+------------+
    / \
     |
     |
+---------------+
| part          |    class name
+---------------+
| container_obj |    attribute variable
+---------------+
| get container |    member functions
| set container |
+---------------+
    / \
     |
     |
+------------+
| container  |    class name
+------------+
| parts      |    attribute variable
+------------+
| get parts  |    member functions
| set parts  | 
+------------+

In this class diagram, each container is a part, and each part is an object. Because of inheritance, each container with include a container_obj and an id number inherited from their ancestors.