473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

php oop .. slightly ot

As of late I have been finding myself using an oop approach rather than a
procedural one. But, it usually consists of a couple base classes and 1
created specifically for a site. I am currently working on 1 that will
basically be used to create divs (or spans) and the styles used with them
for use in creating cms's. As of now, it is a single class that sets css
properties. I just trying to figure out if I should further break down and
create separate classes for each type of property .. i.e. font, border,
margin .. etc.

Here is some example code:

$mod = new Module("Test"); // constructor setting name and Id attributes
$mod -> setBorderWidth(1);
$mod -> setBorderColor("#336633");
$mod -> setSize(300, 200);
$mod -> setPosition(50, 50);
$mod -> setFontColor("#000000");
$mod -> setVisibility("visible");
$mod -> render("HELLO");//creates the opening div (or span) tag and places
the function's argument between that and a closing tag

just trying to get a couple of opinions

--
Chris Mosser
Jul 16 '05 #1
5 1852
With total disregard for any kind of safety measures "Chris
Mosser" <cm*****@comcast.net> leapt forth and uttered:
As of late I have been finding myself using an oop approach
rather than a procedural one. But, it usually consists of a
couple base classes and 1 created specifically for a site. I am
currently working on 1 that will basically be used to create
divs (or spans) and the styles used with them for use in
creating cms's. As of now, it is a single class that sets css
properties. I just trying to figure out if I should further
break down and create separate classes for each type of property
.. i.e. font, border, margin .. etc.

Here is some example code:

$mod = new Module("Test"); // constructor setting name and Id
attributes $mod -> setBorderWidth(1);
$mod -> setBorderColor("#336633");
$mod -> setSize(300, 200);
$mod -> setPosition(50, 50);
$mod -> setFontColor("#000000");
$mod -> setVisibility("visible");
$mod -> render("HELLO");//creates the opening div (or span)
tag and places
the function's argument between that and a closing tag

just trying to get a couple of opinions

--
Chris Mosser


To be honest it sounds more than a little over the top.

If you're just using it as a learning exercise then fine, but is
there really any practical application for such a class?

--
There is no signature.....
Jul 16 '05 #2

"Chris Mosser" <cm*****@comcast.net> wrote in message
news:pZ********************@comcast.com...
As of late I have been finding myself using an oop approach rather than a procedural one. But, it usually consists of a couple base classes and 1 created specifically for a site. I am currently working on 1 that will basically be used to create divs (or spans) and the styles used with them for use in creating cms's. As of now, it is a single class that sets css properties. I just trying to figure out if I should further break down and create separate classes for each type of property .. i.e. font, border, margin .. etc.

Here is some example code:

$mod = new Module("Test"); // constructor setting name and Id attributes $mod -> setBorderWidth(1);
$mod -> setBorderColor("#336633");
$mod -> setSize(300, 200);
$mod -> setPosition(50, 50);
$mod -> setFontColor("#000000");
$mod -> setVisibility("visible");
$mod -> render("HELLO");//creates the opening div (or span) tag and places the function's argument between that and a closing tag

just trying to get a couple of opinions


It'd be much slower than using say some kind of template system, and
the memory usage would be high.
Jul 16 '05 #3


"André Nęss" <an*********************@ifi.uio.no> wrote in message
news:bi**********@maud.ifi.uio.no...
Chris Mosser:
As of late I have been finding myself using an oop approach rather than a procedural one. But, it usually consists of a couple base classes and 1
created specifically for a site. I am currently working on 1 that will
basically be used to create divs (or spans) and the styles used with them for use in creating cms's. As of now, it is a single class that sets css properties. I just trying to figure out if I should further break down
and create separate classes for each type of property .. i.e. font,
border, margin .. etc.

Here is some example code:

$mod = new Module("Test"); // constructor setting name and Id attributes $mod -> setBorderWidth(1);
$mod -> setBorderColor("#336633");
$mod -> setSize(300, 200);
$mod -> setPosition(50, 50);
$mod -> setFontColor("#000000");
$mod -> setVisibility("visible");
$mod -> render("HELLO");//creates the opening div (or span) tag and
places
the function's argument between that and a closing tag

just trying to get a couple of opinions


IMO you are complicating things too much. What is the benefit of your
current solution? If you can answer that question satisfactory your
solution might have something to offer, otherwise you should reconsider.

André Nęss


well, seems like all 3 of you are in agreement, and with me being so new to
oop, I wont argue. Thanks for the input.
--
Chris Mosser
Jul 16 '05 #4
"Chris Mosser" <cm*****@comcast.net> wrote in message news:<pZ********************@comcast.com>...
As of late I have been finding myself using an oop approach rather than a
procedural one. But, it usually consists of a couple base classes and 1
created specifically for a site. I am currently working on 1 that will
basically be used to create divs (or spans) and the styles used with them
for use in creating cms's. As of now, it is a single class that sets css
properties. I just trying to figure out if I should further break down and
create separate classes for each type of property .. i.e. font, border,
margin .. etc.


The important thing is to have a class that contains all the basic
types that show up in your style sheet. After all, the whole thing
with objects is to find what varies and encapsulate it. We're trying
to keep our system modular (www.publicdomainsoftware.org) which means
other people have to somehow get basic types into that object. For
that reason, I'm thinking of doing something like what you considered,
and have a separate object for every basic type in the style sheet.

When I speak of basic types, I mean we have strings that refer to
stuff like "comments" "navElement" and "article". We then have a
process that adds "Whole" and "Headline" and "Maincontent" and "Each"
to the end of each of those types. So, for instance, in our style
sheet we need these entries:

..articleWhole{
}
..articleHeadline{
}
..articleMaincontent{
}
..articleEach{
}

Whole is a div that wraps the next 3, Maincontent wraps Each, and I
don't assume I know a head of time how many entries there might be in
an array, needing the "each" tag.

Why you'd want a separate object for each property is beyond me, but
you haven't given us enough information for us to figure out if it
makes sense in your architecture. Would object print stuff to the
screen? Rewrite a flat file? Just hold one variable? What? If it only
holds one variable, then it sounds like over kill.

It would be enough for my project to have one object that listed all
the basic types for my cms, but as I want to keep it modular, I need
to make each basic type its own object, so 3rd party developers can
add their own types.

Automating style sheets takes a step down the road to the point where
we can do TopStyle stuff internally, in our cms.

You may wonder why we feel we can get away with whole, head,
maincontent, and each. Our philosophy, which has guided recent
development, is that the display of a web page can be thought of as a
series of iterations. There is almost nothing showing up on screen
that isn't coming from an array that's being iterated over. The only
exceptions are the stuff the graphic designers hardcode into the
template, the img tags that Dreamweaver puts there (most of our
designers work in Dreamweaver to design the pages). But as far as our
code goes, we know we can think of everything as an iteration. For
instance, an article has two parts: title and maincontent, so our four
levels wrap things appropriately (though maincontent and each double
wrap the same content). If we have 20 comments on the page, beneath
the article, then they too, get wrapped the same way, over and over
again, the code iterating over some for() loop.

Sometimes custom css classes are needed, but the above gives us
starting point. Also, not everything uses all four. We end up with a
lot of waste classes that we never really need. But then, I find,
smart graphic designers often amaze me with all the stuff they can do
if you give them a surplus of classes to work with.

For me, moving toward oop design was a 2 step process: at first a I
grouped a lot of stuff in a few gigantic classes. For instance, the
forms class had everything in that had anything to do with forms, both
basic methods for building HTML and advanced functions for building
huge forms in an automated way. The hugeness of the class limited code
reuse. The size was ideal for a package, if only I'd been writing in
Java. If it had been Java, it would have been the form package, and
inside I would have had a top level form class that followed the
Command design pattern, and acted as a wrapper for the other classes.
So then it finally occurred to me that I had to refactor. I haven't
really done any refactoring yet. I've a huge SQL class and a huge
form class, and both I hope to break down to small objects, then use
compositon to hold them together. In breaking them down I open the
possibility of someone using their own object instead of mine. Done
right, it should become more modular. That is the whole point of the
Command design pattern.

take care,

lawrence krubner
lk******@geocities.com
www.krubner.com
Jul 16 '05 #5
"lawrence" <lk******@geocities.com> wrote in message
news:da**************************@posting.google.c om...
"Chris Mosser" <cm*****@comcast.net> wrote in message

news:<pZ********************@comcast.com>...
As of late I have been finding myself using an oop approach rather than a procedural one. But, it usually consists of a couple base classes and 1
created specifically for a site. I am currently working on 1 that will
basically be used to create divs (or spans) and the styles used with them for use in creating cms's. As of now, it is a single class that sets css properties. I just trying to figure out if I should further break down and create separate classes for each type of property .. i.e. font, border,
margin .. etc.


The important thing is to have a class that contains all the basic
types that show up in your style sheet. After all, the whole thing
with objects is to find what varies and encapsulate it. We're trying
to keep our system modular (www.publicdomainsoftware.org) which means
other people have to somehow get basic types into that object. For
that reason, I'm thinking of doing something like what you considered,
and have a separate object for every basic type in the style sheet.

When I speak of basic types, I mean we have strings that refer to
stuff like "comments" "navElement" and "article". We then have a
process that adds "Whole" and "Headline" and "Maincontent" and "Each"
to the end of each of those types. So, for instance, in our style
sheet we need these entries:

.articleWhole{
}
.articleHeadline{
}
.articleMaincontent{
}
.articleEach{
}

Whole is a div that wraps the next 3, Maincontent wraps Each, and I
don't assume I know a head of time how many entries there might be in
an array, needing the "each" tag.

Why you'd want a separate object for each property is beyond me, but
you haven't given us enough information for us to figure out if it
makes sense in your architecture. Would object print stuff to the
screen? Rewrite a flat file? Just hold one variable? What? If it only
holds one variable, then it sounds like over kill.

It would be enough for my project to have one object that listed all
the basic types for my cms, but as I want to keep it modular, I need
to make each basic type its own object, so 3rd party developers can
add their own types.

Automating style sheets takes a step down the road to the point where
we can do TopStyle stuff internally, in our cms.

You may wonder why we feel we can get away with whole, head,
maincontent, and each. Our philosophy, which has guided recent
development, is that the display of a web page can be thought of as a
series of iterations. There is almost nothing showing up on screen
that isn't coming from an array that's being iterated over. The only
exceptions are the stuff the graphic designers hardcode into the
template, the img tags that Dreamweaver puts there (most of our
designers work in Dreamweaver to design the pages). But as far as our
code goes, we know we can think of everything as an iteration. For
instance, an article has two parts: title and maincontent, so our four
levels wrap things appropriately (though maincontent and each double
wrap the same content). If we have 20 comments on the page, beneath
the article, then they too, get wrapped the same way, over and over
again, the code iterating over some for() loop.

Sometimes custom css classes are needed, but the above gives us
starting point. Also, not everything uses all four. We end up with a
lot of waste classes that we never really need. But then, I find,
smart graphic designers often amaze me with all the stuff they can do
if you give them a surplus of classes to work with.

For me, moving toward oop design was a 2 step process: at first a I
grouped a lot of stuff in a few gigantic classes. For instance, the
forms class had everything in that had anything to do with forms, both
basic methods for building HTML and advanced functions for building
huge forms in an automated way. The hugeness of the class limited code
reuse. The size was ideal for a package, if only I'd been writing in
Java. If it had been Java, it would have been the form package, and
inside I would have had a top level form class that followed the
Command design pattern, and acted as a wrapper for the other classes.
So then it finally occurred to me that I had to refactor. I haven't
really done any refactoring yet. I've a huge SQL class and a huge
form class, and both I hope to break down to small objects, then use
compositon to hold them together. In breaking them down I open the
possibility of someone using their own object instead of mine. Done
right, it should become more modular. That is the whole point of the
Command design pattern.

take care,

lawrence krubner
lk******@geocities.com
www.krubner.com

thankyou for your view
--
Chris Mosser
Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Edward Diener | last post by:
In an assembly I have a __value enum with some enumerated constants, ie. namespace X { public __value enum MyEnum { ValueA, ValueB }; }
36
by: Hoopster | last post by:
Hello, I know nothing about C++ but want to get started. Is there any good free C++ program that I can try to see if I like programming? I also need a good free compiler. I don't want to...
3
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as...
3
by: jrhoads23 | last post by:
If you look at a standard Button in a .NET Windows Forms app, you will notice its default BackColor is "Control" and it has a 3D raised border which is 2 pixels wide. The outer edge on the left and...
9
by: easy | last post by:
I start off with an interface class that has no data members and a handful of virtual functions. First Question: is that allowed ? I then derived from this class and it gets included into...
1
by: Phil Latio | last post by:
I have a number of spreadsheets, each with between 1000-6000 rows (each row is a property) and they all need to be combined into a single database. Each spreadsheet contains slightly different...
1
by: Tim Haughton | last post by:
For the .Net framework 3.0, the download link is... http://go.microsoft.com/fwlink/?LinkId=70848 If I'm creating an installer, how do I find the permalink for redistributables? For example, I...
3
by: pauldepstein | last post by:
I am using the latest version of Visual c++ on windows XP. I am trying to build a project and get a lnk1104 error regarding a file of the form .../../ ProjectName.lib No other errors, just this...
4
by: Ken Fine | last post by:
I know about this: http://silverlight.net/forums/14.aspx and this: http://forums.asp.net/1127.aspx Silverlight Beta 2 was announced at TechEd. I was impressed. When does Silverlight get a...
3
by: Michiel Overtoom | last post by:
Paul & Robert wrote... I occasionally have a need for printing lists of items too, but in the form: "Butter, Cheese, Nuts and Bolts". The last separator is the word 'and' instead of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.