Several months ago I started a thread with the title "What is/is not
considered to be good OO programming" which started a long and
interesting discussion.
I have condensed the arguments into a single article which can be
viewed at http://www.tonymarston.net/php-mysql/good-bad-oop.html
I fully expect this to be the start of another flame war, so sharpen
your knives and get stuck in!
Tony (you do it your way and I'll do it better) Marston http://www.tonymarston.net/
Jul 17 '05
52 6407
Matty wrote: Wow, it's come back to life again!
Asbestos manufacturers everywhere must be looking forwards to this one!
;p
Matt
FWIW, I still think it's better to have 12 different instances,
rather than 12 different classes <duck />... Not read it all yet,
just a quick search! I'll have a good read through tomorrow, but
I do think there aren't sufficient differences between tables in a
database to justify having a separate class to handle each table,
when a separate instance of a suitably generic class would handle it
OK.
I am definitely a TMTOWTDI kind of person, though, and I do agree
that fundamentally, if the software works, then it's good.
Matt
>> "Tony Marston" <to**@marston-home.demon.co.u k> wrote in message news:75******** *************** ***@posting.goo gle.com...
<snip>
http://www.tonymarston.net/php-mysql...tml#2003-12-05
(Yet Another Follow Up...)
Can't help wondering what the object composition argument was, and how
on earth you could do it in a logical manner.
A table "has a" page of records?
A page of records "has a" table (what would it do if it didn't?)
Personally, yeah, I think composition isn't the way to do it...
/me thinks How about a table "has a" table perhaps???
;p
Matt
André Næss <an************ *********@ifi.u io.no> wrote in message news:<bq******* ***@maud.ifi.ui o.no>... Tony Marston:
Object composition was also the crux of my argument, i.e.: where you see only inheritance, I see inheritance and composition. From this we can only deduce that you in fact did not properly understand my argument. You argument is irrelevant as it serves no useful purpose when discussing a single abstract class.
I wasn't discussing a single abstract class. I was discussing a solution to a problem. The single abstract class and proliferation of new classes is *your* solution. I tried to argue that a different, and IMO better approach was possible.
It may seem better in your opinion, but to my mind it is different
without any obvious benefits, so there is no point in changing.
You didn't bother to learn about object composition until *now*, yet you disagreed with my idea of using it in your case.
Object composition is not listed among the principles of OOP, so I
ignored it. When I did read about it the first thing that I saw was
that it was considered as an alternative method of dealing with
complex hierarchies. As I do not have a complex hierarchy (just two
levels) there seems no point in investigating it any further.
In other words, you had decided that your solution *is* the best even before you started the discussion,
I never said it was the best, I merely said that it is simple and it
works. As a follower of the KISS principle this is VERY important. Why
waste time on a complex solution if a simple one works?
despite the fact that you did not know much about OO.
André Næss
It is true that I have not been taught any OO, but that means that I
have not been taught the wrong things. What I have read about OO tells
me that objects are not that much different to components, and as I
have been working with a component-based development language for the
last 10 years all I did was to take my component-based design and
convert it to object-based. Simple and effective.
The fact that I do not do OOP in the way that you do it is irrelevant.
I can achieve rapid results my way, so my way is good for me (and a
few others according to the emails I have received).
Tony Marston http://www.tonymarston.net/
Tony Marston wrote: "Philipp Lenssen" <in**@outer-court.com> wrote in message news:<bq******* ******@ID-203055.news.uni-berlin.de>... André Næss wrote: I was thinking the same. I saw the article, looked for "compositio n", couldn't find it, and went away.
Just for you I have added a section on object composition. I hope you like it.
http://www.tonymarston.net/php-mysql...tml#2003-12-05
You should differentiate between "has a" and "is a". I believe I
recently posted this here and the idea is neither mine nor new.
Inheritance examples in books often go by the examples of employees.
And employee "is a type of" person. So it would not make sense to use
object composition. (Not if person and employee are intended to be the
same anyway.) Because an employee shares attributes of a person but
includes his own.
Now let's say I have a class "webpage". Now this "webpage" has a
complex module "binary_ima ge" which will render images. You would use
simple object composition by creating a new instance of "binary_ima ge"
within "webpage".
Why is it composited and not inherited?
Because the webpage "has a" binary image. However, it's wrong to say
binary_image "is a type of" webpage. 'Cause it's not.
This was just an example. Usually I don't use global instances of
objects either in a class. Usually they just go right into the
function. E.g. using the file-system object from within a class on a
Windows server. Or handling XML.
And object composition structures the code and can make it more
readable. It's often more natural. But whatever approach suits you.
Don't forget however that if you're working in a team you can't just
say "my approach is better 'cause I like it and everyone should code
the way they want", because code must be managed by others. You
wouldn't expect your code to be rewritting from scratch or highly
refactored if you were sick for a week and someone else had to go
through it. So you should write code in ways accepted and used in your
team, and to find the best solution you must argue beyond personal
taste. Sometimes, you may even need to compromise.
"Doug Hutcheson" <do************ *******@nrm.qld .gov.au> wrote in message news:<B%******* ***********@new s.optus.net.au> ... "Tony Marston" <to**@marston-home.demon.co.u k> wrote in message news:75******** *************** ***@posting.goo gle.com... "Philipp Lenssen" <in**@outer-court.com> wrote in message news:<bq******* ******@ID-203055.news.uni-berlin.de>... André Næss wrote:
> Tony Marston: > > > > I have condensed the arguments into a single article which can be > > viewed at > > http://www.tonymarston.net/php-mysql/good-bad-oop.html > > > I just think it's funny that you still don't understand object > composition. In your article you write: "How do you share code in OO > systems? Through inheritance.", not even mentioning object > composition. Object composition was also the crux of my argument, > i.e.: where you see only inheritance, I see inheritance and > composition. From this we can only deduce that you in fact did not > properly understand my argument. That doesn't make the discussion any > easier. >
I was thinking the same. I saw the article, looked for "compositio n", couldn't find it, and went away.
Just for you I have added a section on object composition. I hope you like
it. http://www.tonymarston.net/php-mysql...tml#2003-12-05
Kiss, kiss
Tony Marston http://www.tonymarston.net/
Tony, A trifle defensive <grin>, but wholly correct. As another 25+ programmer, I can state without too much fear of contradiction that the customer pays me to solve his problem, not to write code which meets the approval of the paradigm police. More power to you, you rabid radical you! Cheers, Doug Hutcheson
People tend to describe me more as revolting than rebelling. Is there
a difference? :)
Tony Marston http://www.tonymarston.net/
Matty <ma*******@askm enoquestions.co .uk> wrote in message news:<cG******* *************@w ards.force9.net >... Matty wrote:
Wow, it's come back to life again!
Asbestos manufacturers everywhere must be looking forwards to this one!
;p
Matt FWIW, I still think it's better to have 12 different instances, rather than 12 different classes <duck />...
According to the principles of OO you are not supposed to instantiate
an abstract class then feed it the implementation details, you are
supposed to put the implementation details in a subclass. If I were to
use the keyword 'abstract' in the class definition (as PHP 5 will
allow) you will find it impossible to instantiate an abstract class
directly, in which case you MUST use a subclass.
So, if I have 12 database tables each with a totally different set of
implementation details, then (according to the above-mentioned
principle) I must create 12 subclasses. I am right and you are wrong,
so score 1-0 to me :)
Not read it all yet, just a quick search! I'll have a good read through tomorrow, but I do think there aren't sufficient differences between tables in a database to justify having a separate class to handle each table, when a separate instance of a suitably generic class would handle it OK.
I am definitely a TMTOWTDI kind of person, though, and I do agree that fundamentally, if the software works, then it's good.
Matt
If it works then it is not wrong. But if method A is easier to
implement than method B, then (all other things being equal) method A
is better.
Tony Marston http://www.tonymarston.net/
Matty <ma*******@askm enoquestions.co .uk> wrote in message news:<YN******* *************@w ards.force9.net >... "Tony Marston" <to**@marston-home.demon.co.u k> wrote in message news:75******** *************** ***@posting.goo gle.com...
<snip>
http://www.tonymarston.net/php-mysql...tml#2003-12-05
(Yet Another Follow Up...)
Can't help wondering what the object composition argument was, and how on earth you could do it in a logical manner.
A table "has a" page of records?
A page of records "has a" table (what would it do if it didn't?)
Personally, yeah, I think composition isn't the way to do it...
/me thinks How about a table "has a" table perhaps???
;p
Matt
A table has 4 legs and a set of drawers. Now, if I were to drop the
drawers and spread the legs..... :)
Tony Marston http://www.tonymarston.net/
Tony Marston wrote: FWIW, I still think it's better to have 12 different instances, rather than 12 different classes <duck />... According to the principles of OO you are not supposed to instantiate an abstract class then feed it the implementation details, you are supposed to put the implementation details in a subclass. If I were to use the keyword 'abstract' in the class definition (as PHP 5 will allow) you will find it impossible to instantiate an abstract class directly, in which case you MUST use a subclass.
Depends on what you're doing with the "Table" class - if it's just a
question of iterating through the records, then one generic table class
would cover the vast majority of applications, without subclassing.
$parts = new Table ('partslist', 'partid', array('partid'= >'Part ID number',
'pdesc'=>'Descr iption', 'stockcount'=>' Number in stock'));
$customers = new Table ('customers', 'custid', arrya('custid'= >'Customer #',
'tel'=>'Contact Phone', 'sic'=>'SIC Industry Code'));
should work fine.
The other comment I'd make on this, is that "abstract" != "abstractio n".
Just because describing a table as
tablename
primarykey
fieldlist
is an abstraction, doesn't mean you need an abstract class for this - a "concrete"
class is fine for this model.
Personally, if I were writing a DB class lib, I'd have something along the lines of
Dataset
Table is-a Dataset
Query is-a Table, has-a SQL query
etc, etc
with Dataset being abstract, but that's just my take on it. So, if I have 12 database tables each with a totally different set of implementation details, then (according to the above-mentioned principle) I must create 12 subclasses. I am right and you are wrong, so score 1-0 to me :)
Yes and no, I would say. Yes, 12 tables requiring totally different handling
code would require 12 different classes. But the original tutorial, as I
remember it, showed 12 analogous tables (treated as a list of fields, etc)
that could all be handled by the same class as different instances, easily.
1-1 perhaps ;p If it works then it is not wrong. But if method A is easier to implement than method B, then (all other things being equal) method A is better.
Couldn't agree more. I just think that your original base class was nearly there
for something that would handle any table, just given a list of fields to use!
Wonder how many months the total lifetime of this thread can be...
Matt
"Tony Marston" <to**@marston-home.demon.co.u k> wrote in message
news:75******** *************** **@posting.goog le.com... "Doug Hutcheson" <do************ *******@nrm.qld .gov.au> wrote in message
news:<B%******* ***********@new s.optus.net.au> ... "Tony Marston" <to**@marston-home.demon.co.u k> wrote in message news:75******** *************** ***@posting.goo gle.com... "Philipp Lenssen" <in**@outer-court.com> wrote in message news:<bq******* ******@ID-203055.news.uni-berlin.de>... > André Næss wrote: > > > Tony Marston: > >
> > > > > > I have condensed the arguments into a single article which can
be > > > viewed at > > > http://www.tonymarston.net/php-mysql/good-bad-oop.html > > >
> > > > I just think it's funny that you still don't understand object > > composition. In your article you write: "How do you share code in
OO > > systems? Through inheritance.", not even mentioning object > > composition. Object composition was also the crux of my argument, > > i.e.: where you see only inheritance, I see inheritance and > > composition. From this we can only deduce that you in fact did not > > properly understand my argument. That doesn't make the discussion
any > > easier. > > > > I was thinking the same. I saw the article, looked for
"compositio n", > couldn't find it, and went away.
Just for you I have added a section on object composition. I hope you
like it. http://www.tonymarston.net/php-mysql...tml#2003-12-05
Kiss, kiss
Tony Marston http://www.tonymarston.net/
Tony, A trifle defensive <grin>, but wholly correct. As another 25+
programmer, I can state without too much fear of contradiction that the customer pays
me to solve his problem, not to write code which meets the approval of the paradigm police. More power to you, you rabid radical you! Cheers, Doug Hutcheson
People tend to describe me more as revolting than rebelling. Is there a difference? :)
Tony Marston http://www.tonymarston.net/
"Rebellent" , perhaps?
<g,d&r>
"8-)
"Tony Marston" <to**@marston-home.demon.co.u k> wrote in message
news:75******** *************** **@posting.goog le.com... Matty <ma*******@askm enoquestions.co .uk> wrote in message
news:<YN******* *************@w ards.force9.net >... > "Tony Marston" <to**@marston-home.demon.co.u k> wrote in message > news:75******** *************** ***@posting.goo gle.com...
<snip>
>> >> http://www.tonymarston.net/php-mysql...tml#2003-12-05 >>
(Yet Another Follow Up...)
Can't help wondering what the object composition argument was, and how on earth you could do it in a logical manner.
A table "has a" page of records?
A page of records "has a" table (what would it do if it didn't?)
Personally, yeah, I think composition isn't the way to do it...
/me thinks How about a table "has a" table perhaps???
;p
Matt
A table has 4 legs and a set of drawers. Now, if I were to drop the drawers and spread the legs..... :)
Tony Marston http://www.tonymarston.net/
Ah - a rebellent furniture fetish!
Strange fruit, Tony, strange fruit indeed.
"8-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: darwinist |
last post by:
What PHP Represents
There is no shortage of complaints one could make about php as a
language, and although the list does shrink with each release, some of
them are inherent to the origins and development process of this, the
most popular of the web-based, server-side, glue-languages.
That said, most descriptions of what is good about php, fail to do it
justice. Although they are generally enthusiastic and sometimes
fanatical, no...
|
by: perseus |
last post by:
I think that everyone who told me that my question is irrelevant,
in particular Mr. David White,
is being absolutely ridiculous. Obviously, most of you up here
behave like the owners of the C++ language. A C++ interface
installation IS ABOUT THE C++ LANGUAGE! The language
does not possess the ability to handle even simple file directory
manipulation.
Those wise people that created it did not take care of it. So, BOOST
is a portable...
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: Hermawih |
last post by:
Hello ,
I want your opinion about this .
In order to say it clearly , I think I have to describe it in long sentences .
I could consider myself as Intermediate/Advance Access Developer ;
Intermediate/Advanced Database designer .
Because of the requirements , I must create Web Application . Access Pages
is not suitable for that so I think about learning VB Net / ASP Net . I am
|
by: Vishal Naidu |
last post by:
i m new to the C world...
i ve been told by my instructors not to use goto stmt..
but no one could give me a satisfactory answer as to why it is so..
plz help me out of this dilemma, coz i use a lot of goto in my codes....
| |
by: Xah Lee |
last post by:
in March, i posted a essay âWhat is Expressiveness in a Computer
Languageâ, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic paper written on this
subject.
On the Expressive Power of Programming Languages, by Matthias
Felleisen, 1990.
http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
|
by: TB |
last post by:
Hi Everyone on comp.lang.c++:
I am thinking about learning a programming language and I want to
decide whether it is worthwhile spending my time learning the C++
programming language.
I am a starting C++ programmer. By that I mean that I have written one
small application in C++ on a real job that required some modular
programming. I am also familiar with the Object-Oriented Programming
techniques although I haven't used them...
|
by: clintonG |
last post by:
Every single time neophytes or converts ask about naming and style
conventions what are they told by the majority consensus? The answer is "do
what you prefer but do so consistently" right? Yes, that's right, that's
exactly what is said. People joining a team of developers are also
encouraged to cooperate with their peers and adopt what has already been
established right? Yes, that's exactly what is encouraged.
Teamwork and cooperation...
|
by: Mason |
last post by:
I've been working to become competent at making websites. My learning path
has been:
html -css- paintshop pro -javascript -php/mysql
I'm getting somewhat proficient at php/mysql (although I have plenty to
learn - I haven't even started on gd library) and want to think about my
next step.
Any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |