In: Computer Science
(a) Explain at least TWO (2) major aspects of an object-oriented programming (OOP). Provide suitable examples,
Explanation of two major aspects of an Object-Oriented
Programming (OOP) with suitable examples:
The different aspects, capabilities, or features are
encapsulation, inheritance, and
polymorphism.
Encapsulation uses, and makes modularity a mandate, forcing it to
be used wherever applicable, and appropriately.
Inheritance passes the characteristics of knowledge in a downward
direction.
Polymorphism, on the other hand, is a completely different concept,
wherein it is about taking any shape.
From a different OOP paradigm perspective, classes and objects are the two main aspects. A "class" is used to create new types, whereas "objects" are simply class instances. These two aspects are important and are building blocks of code in a program.
In Swift:
"Class" example:
class Motorcycle
{
}
An "Instance" example to create instances of a class:
class Motorcycle
{
}
let yamaha:Motorcycle = Motorcycle()
From a, yet different perspective, the other aspects of OOP are properties and functions (methods). A property can be considered as a variable belonging to a class and storing information belonging to an instance of a class. A method is a function belonging to a class and executes tasks belonging to an instance of a class.