![]() |
Class inside a class(?)
Hey all, I have a question for you.
I Have one class, lets call it for example "table". inside that class I want to insert another class, for example "columns". but I don't need the "columns" class outside of the "table" class, only inside it, and only 1 columns class will be needed within a table class. PHP Code:
|
|
Quote:
I'm talking about that the "columns" class will be only available within the "tables" class, and cannot be available outside of the "tables" class. |
Inside your table class, just add a member variable which is an instance of the columns class.
For example (only an example!): PHP Code:
|
Quote:
PHP Code:
So, Salathe, what do you say? Also, if i use your way, is there anyway to get to the "parent element" from columns class? (so i can reach "table" class from "columns" class functions) |
If you create a columns object inside the table object,than you cannot access that object directly out of the object.
For example PHP Code:
|
Why dont you just inherit an abstract class?
PHP Code:
Note: You must have PHP5 to do this, php4 doesnt support abstraction if I recall |
Quote:
what i did is something like this, and i want to know if it's correct : PHP Code:
|
Quote:
|
Quote:
|
not looking at this properly, i would say the only other way of doing it is to use an abstract.
Just to clear somthing up, doesnt a table have columns anyway (thinking from an object point of view, a table has columns and rows), so the table object should have the ability to add columns so i dont see the use in creating an extra object for columns, im sorry if im just being a bit thick if that isnt the case, i must be on one of my stupid head days. |
Quote:
|
I can relate to that i have been there myself mate, when you don't think things through properly and end up making a relatively simple task 20 times harder and then tearing your hair out because there isn't any articles to help :D.
Good luck with the rest of the script. |
| All times are GMT. The time now is 07:31 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0