Friday, February 13, 2015

Summary of Object-Oriented Programming Concepts

Concepts of Object-Oriented Programming

Object-Oriented Programming (OOP)

OOP is a programming paradigm that is based on objects, rather than other things, like imperative, declarative.

Object

Object is an instance of a class.

Class

Class is a combination of attributes and methods. It can be pre-defined, or can be written by the programmer.

Subclass

Subclass is a secondary class under the superclass. It inherits all the attributes and methods of the superclass. It can also build it own attributes and methods by overriding the original one.

Upperclass

Upperclass is the parent class of a subclass.

Inheritance

Inheritance (verb: to inherit) means that the subclass can possess all the attributes and methods the superclass have.

Overriding

Overriding (verb: to override) means that the subclass can override some attributes or methods inherited from the upperclass.

Attribute

Attribute defines the property of a class. In python, it is defined in __init__ and attributes are often inserted by parameters.

Initialization in a Class (__init__)

Initialization (verb: to initialize) is where we define the attributes and parameter of a class. It must be defined in a class. In python, it is defined by "__init__" in python.

Self

Self represents the class itself inside a class.

Parameter

Parameter means the variable taken by a class. Parameters always become attributes when initializing.

Argument

Argument is the specific parameter in a class.

String in a Class (__str__)

__str__ returns a string that contains the public face of the class.

Representation in a Class (__repr__)

__repr__ returns a string that contains the exact representation of the class. Sometimes it is same as __str__.

Equivalence in a Class (__eq__)

__eq__ compares whether 2 objects are equal and therefore returns a boolean.

Abstract Data Type (ADT)

ADT is a kind of data type that is abstract.

Recursion

If a function uses itself in the function, then it uses recursion.

Stack

Stack is a class that users can only reach the top of the stack (the last item of the list).

Tree

Tree is a class that has its value and children.

No comments:

Post a Comment