Welcome! Log In Create A New Profile



Posted by Mariuspienaar 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
August 11, 2013 04:19PM
Good day
Where we have to create the OOP_constructor page. Below the class we have to create a new object, and pass the required data (manufacturer and colour) to the constructor function. I don't understand why there are set and get Functions? Because I use a construct function for all the data and a Display function, after the class i create the new object and call the display function to display the data of the constructor.So i see it unnecessary for set and get, but each set and get functions counts two points.
avatar Re: Constructors
August 11, 2013 05:42PM
You use the set method to change the data values in an object, eg: In a Customer class, what if an existing customer changes their phone number ? You would use myCusttomer.setPhone(number) to do that.

You use the get method to read a data value from your class. eg: If you only want to display Customers with a particular surname, you would need to use a myCustomer.getName() method.
Re: Constructors
August 11, 2013 08:25PM
Thanks for your reply bigron11

I get your point of view,but for me its just like alot of unnecessary code that will take extra time, just imagine the hundreds of set,get,set,get's that one must write. Your example of telephone nr, I will just code a new object for the numbers then change that value of that object parameter if a customer wants to change their phone number. Actually if i could have it my way, i was just gonna put it in an array and loop it through, but well its constructors.
avatar Re: Constructors
August 11, 2013 09:21PM
Getters and setters are a normal part of OOP and you may just as well get used to them.
Basically they are just a means of providing public access, in a controlled manner, to data members which are otherwise encapsulated within objects of a class.

It is quite a big jump from structured programming to OOP, but when you get used to OOP you will wonder how / why you ever did it any other way.
Sorry, only registered users may post in this forum.

Click here to login