Join GitHub today
Object Oriented Programming
A normal Class is already encapsulated because it contains the attributes and methods required for that type of Object. So, encapsulation can mean to create a class, and set its attributes and methods. By Encapsulation, the source is protected from any corruption. It allows a developer not to touch the encapsulated Class, unless there is a requirement to add methods and attributes to the object.
One example of Dependency Injection is the relation between Author and Question classes in a Wiki class. The Question class can not exist without an Author attribute. So, instead of creating a variable which stores the Author Class, programming the attributes and methods of the Author without calling the Author Class can make a class more stable because the Author Class is responsible of its own self, even though Question is dependent on the Author.
Because the Author class do not need to be an Author per se, You can inject Accountant, Programmer, or a Person class to create the Wiki.
Looking at the long term, Dependency Injection allows the entire program to become more stable because removing one class can less likely affect the entire program.
General Programming Terms
Polymorphism can refer to anything that can result to any type of Object or code. Here are some examples:
- A function which can given a result of either JSON or XML output.
- A function which accepts strings or integers. The process can be addition of numbers if integer, or concatenation of the given strings.
- An abstract Animal class method named "talk", can exist in all Animal types such as Dog and Cat Classes, which outputs "meow!" or "bark!"
Polymorphism can take multiple types of variables, and give the results depending on the given data.
Static and Dynamic Programming Languages
A static programming language requires the developer to compile the source code, and convert it to binary code. Some examples are Java, C#, C++, etc
A dynamic programming language does not require compilation. Some examples are PHP, Python, and Javacript.