timvw wrote:Hockey wrote:
1) HTML does not belong inside a class...thats the worst example of OOP...
I'm aware that there are many projects where static html with embedded code will lead to a better/faster solution for them.
But why can't a set of classes model a HTML document and it's elements?
And why would that model be the worst example of OOP?
Hockey wrote:
If I want to use your class, who says I want the header your class outputs? HTML is better left for template engines...
Who says you have to use the default method to generate a header? Who says my class would output anything?
Why is HTML better left for template engines?
Why can't a template engine be OOP?
Hockey wrote:
2) And thats cool, but again it forces me into using it's database abstraction layer doesn't it? What if I want to use AdoDB or my own???
The consequence of writing OO code is that most of the times you develop several layers simply to allow yoru code to flexible and reusabe.
And yes, hibernate uses a layer for it's dialects and it uses a database-access layer, being the (more or less) only standard for Java, JDBC.
Hockey wrote:
For me, reusability is "everything" when writting an class...if I can't reuse the class exactly as is in a later project I might as well save myself the time of writing extra class syntax (I'm that lazy yes) and proceed to writing fast efficient SQL functions instead of member functions.
So you are trying to say that member functions can't be fast efficient SQL member functions?
Hockey wrote:
If you have CPerson class which maps to your very own database structure, it's very likely both the schema and your object properties, methods, etc will change in your next project...if you add an age field to your schema, you need to update your class...which is NOT reusable in the pure OOP sense of the word.
What is the pure OOP sense of reusable then?
The way i see it you can easily inherit from that CPerson and add a age property.
If you had actually looked at Hibernate you would have seen that it's perfectly possible for the scheme generator to take care of this too.
1) Not saying you can't

Just that you shouldn't IMHO
I never said classes shouldn't model an HTML document and it's elements...in fact there is a well known class that does just that, it's called DOM
But a DOM is, whats the word, an abstraction of a HTML document, there is no actual HTML code stored in a DOM, but rather a structured list of nodes which represent HTML tags.
That is an example of a class being reusable.
I guess what I'm trying to say, is embedded HTML in a class fixes that class strictly to your project, cuz for one wouldn't use it!
However a good example of a class like a DOM class (assuming technically it's up to par, bug free, compliant API, etc) I would use if nessecary.
Can you give any arguments why you wouldn't use a DOM class if needed (outside of it's code bloat, etc)? I think you'd be hard pressed to find any, because it's a great example of OOP.
Who says you have to use the default method to generate a header? Who says my class would output anything?
Why is HTML better left for template engines?
Why can't a template engine be OOP?
Show me an example of how you would use HTML in a class, I think one of us is missing something here
Why would your class contain any HTML (whose whole purpose is to render into visual elements on screen) not output anything?
Again I need an example of what your saying...
HTML is better left for a template engine, for the same reason parsing is better left for EBNF that hand coded. The same reason we use SQL instead of reading a file directly and executing hand coded queries on arrays. The same reason we use HTML instead of an element API:
Code: Select all
$obj = new CTableElement();
$obj->setAttribute('width', '100%');
Imagine coding an entire HTML document this way? It's tedious and hard on the eyes.
So you are trying to say that member functions can't be fast efficient SQL member functions?
Not even close, I understand the internals of how OOP works compared to procedural code, so I know first hand that a function call is only slightly faster than a class method call. With the exception of dereferencing the 'this' pointer, I would say there pretty much equivelant.
What is the pure OOP sense of reusable then?
The way i see it you can easily inherit from that CPerson and add a age property.
If you had actually looked at Hibernate you would have seen that it's perfectly possible for the scheme generator to take care of this too.
Yes you can, but using straight SQL without any of these mapper frameworks (Hibernate??) it would require alot of work...
I'll have to look into this Hibernate...but first I have to figure out Active Record
Cheers
