Changes

Object Oriented programming

2,185 bytes added, 20:26, December 12, 2019
Expanded and clarified
'''Object Oriented programming '''(OOP) languages are based around the paradigm of objects that interact with each other to produce functionality. There are many [[programming language]]s that are designed around object oriented principles, such as [[Java]]. A class is a definition of an object and contains data and/or functions. Functions within a class are called "methods".
== Objects Definition==Objects are components of an object oriented languageObject Oriented programming is defined by three things: inheritance, polymorphism, consisting of properties and methodsencapsulation.
An object ===Inheritance===Inheritance is also known as a Type the ability for one class to use the data and methods of an ancestor class (or Classmultiple ancestor classes if multiple inheritance is allowed), rather than having to define those again within a new class. If class B inherits from class A, then class A is called an ancestor class of B, and class B is called a descendant class of A. A decedent class instance can be used in place of any ancestor class instance, but an ancestor class instance cannot be used in place of a descendant class instance.
=== Polymorphism ===Polymorphism allows an object to appear as another be used in place of an ancestor objectwithout the code that is using it having to know about the descendent. This means that a complex object can appear to be a simple one. The example below shows that you can have a specific model of car, such as the [[Model T]], which looks like and acts like a normal car. Polymorphism can be implemented in different ways. Smalltalk implemented it via messages. Most compilers that support OOP implement a virtual method table, which is an array of method pointers as per the CORBA standard.
=== Example (Java)Encapsulation===Encapsulation means that the data used by a class is defined within the class itself, rather than having to resort to global data.
== Classes and Instances ==
A class is a definition. In most languages, a class is a data type. An instance is an instantiation of a class. It can be considered in terms of a real-world analog: the designs for a pickup truck are akin to a class. An actual pickup truck build according to those designs is an instance of that class. The term "object" is often used to refer to either the class, an instance, or the general concept. The data within an instance is referred to as "instance data".
 
==Constructors and Destructors==
A constructor is a class method that is automatically called when an instance of the class is instantiated. The purpose of the constructor is to set up the new instance. A destructor is a method that is called when an instance of the class is destroyed. The purpose of the destructor is to clean up just prior to the class being deleted. Typically this includes freeing memory pointed to by instance data. Some programming languages support special constructors called "copy constructors" which are called when an instance is created as a copy of another instance.
 
== Example (Java)==
<pre>
public class ModelT extends Car {
SkipCaptcha
255
edits