Major Project theme : Object-Oriented Programming (OOP)

Object-oriented programming ( OOP )



This section will provide an overview of the basic approach to Object-oriented programming. OOP is a programming paradigm fundamental to many programming languages, including Java, C++, JavaScript and Python. Object-oriented programming is about a system as a collection of objects, where each object represents some particular part of the system.(Lee, 2019) Objects contain functions as methods and data as pairs of properties and values. An object provides a public interface to other objects or code that wants to use it but keeps its own private, internal state. The rest of the code doesn’t have to know about what is happening inside the object.(MDN, 2022)



Classes

When a developer design an object he creates an abstract definition representing the type of the object in the system. For a better example. In a situation where a developer creates a school, he might want to have objects representing professors. Every professor has some properties in common: they all have a name, surname, age, and subject that they teach. Furthermore, every professor can do certain things: they can all grade a paper and they can introduce themselves to their students.(MDN, 2022)

For example, Professor could be a class in code. The definition of class lists the data and methods that every professors has.

In pseudocode to explain it more clearly, a Professor class could be written like this:

(MDN, 2022)

This defines a Professor class with:
    -Two data properties name and teaches
    -Two methods: grade() to grade a paper and
      introduceSelf() to introduce themselves.


On its own, a class doesn’t do anything. It is a template for creating a concrete object of that type of data which was defined in class. Each concrete professor we create is called an instance of the Professor class. The process of creating an instance is performed by a special function called a constructor. The developer passes values to the constructor to initialize the new instance. This means the template is one but it can create a similar objects with different values of properties or methods.(MDN, 2022)



Generally, the constructor is written out as part of the class, and it usually has the same name as the class itself:

(MDN, 2022)

 







This constructor takes two parameters, so we can initialize the name and teaches properties when we create a new professor.




Now that we have a constructor, we can create some professors. Programming languages often use the keyword new to signal that a constructor is being called.

(MDN, 2022)

This creates two objects, both instances of the Professor class.








The benefits of object-oriented programming are so many that it's hard to quantify, once you understand how this approach work, you'll only wonder why you didn't find out it before. One of the advantages is modularity - working with object-oriented languages you know where to look for a problem when something goes wrong in the code, you don’t need to look through thousands of lines of code, just find the right object. Another advantage is flexibility - objects can be easily modified and share functions, which accelerates work and the code debugging process. (Lee, 2019)









Reference

MDN, M.D.N.contributors (2022) Object-oriented programming - learn web development: MDN, Learn web development | MDN. Available at: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_programming (Accessed: October 28, 2022).

Lee, G. (2019) Modern programming: Object oriented programming and best practices. www.ebsco.com. Available at: shorturl.at/nvHT2 (Accessed: November 5, 2022).

Comments

Popular posts from this blog

Software and Hardware skills