Skip to content
Advertisement

Transform a average php code to OOP (set_get) [closed]

I have this code I want to Transform to OOP (Set-Get) what the code do is to take some numbers and find the average.

JavaScript

it`s my first time learning this i need to do it with class (set/get) : this what i did i:

JavaScript

Advertisement

Answer

A non-complete definition (but all you need to know for this example):
In object oriented programming (OOP) classes are used to link/group together data and its behavior / operations you can do with that specific data. OOP is not set/get!!!

In your specific case the data is an array of numbers and the operation is the average calculation. Another operation would be the total calculation.

Very basic example of what you need:

JavaScript

Further on, other operations can be added to your class. For example, when you want to append additional numbers to the original array (method appendItem()):

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement