Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Definitions and Theory (Part I) - Is this right?

Some questions and answers that I've assembled in an effort to better understand OOP. If you could read through them and either affirm my answers as correct, or alert me to my being less than accurate...

Here we go:

What's a Construct?

A construct is a function that you use to define properties in the context of your class.

What's an Accessor?

An Accessor is a function that is used to define a Property for a Class. The Property has to be assigned a visibility value of "private' in order for it to work, but this is a handy way to manipulate Property values within a Class (http://coursesweb.net/php-mysql/php-oop-accessor-destructor).

What's the difference between Construct and Accessor if they're both used to define a Property?

(I'm weak on this one...)

Flexibility. With an Accessor you can make changes on the fly, but with Construct, you're establishing a programmatic foundation that doesn't allow for the Property values to be changed as easily...?

I'll be posting several questions today in the context of "Definitions and Theory." Feel free to weigh in however and whenever you would like. Thanks in advance for helping me get my mental arms around all of this...?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

If you can, please post the links to the material you're asking about.

The "Accessor" concept is also called "setters and getters" since it provides a formalized way of adding/updating and retrieving data from an object.

If by "Construct" you really mean "Class Constructor" it's simply a function (method) that is run when an object is instantiated from a class.  You do not necessarily use it to define properties.  It just takes care of "housekeeping" tasks at instantiation time.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

I do like books, Ray, but I find that I learn best by "doing," and while I don't have a completed page or link to show you yet, I hope to be there within the next several hours, but not at the expense of being able to understand "why" what I've coded is correct.

As far as "construct"...

Based on your counsel and this link: http://php.net/manual/en/language.oop5.decon.php, what I'm perceiving is that while Construct can facilitate the definition and Property values, it can be used to establish any one of a number of crucial starting points. To use your verbiage, it's "housekeeping" and the definition of Property values is but one of the things that fall under that heading.

Better?
Accessors...

Property accessors provide a clean, easy to understand and unified syntax for get/set accessors. They allow read and write requests (gets and sets) from a class property to be run through a method first. This method can perform validation or a transformation, or update other areas of the class. Properties do not even have to be associated with a class member, and can generate their own data on-the-fly. (https://wiki.php.net/rfc/propertygetsetsyntax-v1.2)

Whereas "construct" can be used to facilitate any one of a number of "housekeeping" tasks, an Accessor's role is focused exclusively on Class Properties.

It's a handy tool to have in that you can establish "starting points" on the fly and in that way preserve an adaptive dynamic to your functionality.

I don't have an example of this yet. It was mentioned in some documentation as an aside and I wanted to understand what it was.