Solved

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

Posted on 2014-11-07
4
64 Views
Last Modified: 2014-12-02
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...?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40429012
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.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40429026
Eww, one other note.  I've only been looking at it for a few minutes and I've already found some pretty serious errors in coursesweb.net.  You might want to step back from that questionable site and start by reading the information from the horse's mouth:

http://php.net/manual/en/language.oop5.php

If you like books, these two are worth your time and money:
http://www.amazon.com/PHP-Object-Oriented-Solutions-David-Powers/dp/1430210117
http://www.amazon.com/gp/product/143022925X/
0
 

Author Comment

by:brucegust
ID: 40429062
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?
0
 

Author Comment

by:brucegust
ID: 40429102
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question