[Tutor] get name of calling class at runtime

Alan Gauld alan.gauld at btinternet.com
Sat Aug 22 09:54:22 CEST 2009


"Kent Johnson" <kent37 at tds.net> wrote

>>> can group a bunch of SQL statements in one place; they're currently
>>> scattered all over the program and it's getting unwieldy).
>>
>> Normally in an OO program the SQL for each class is in the methods for 
>> that
>> class. That way any changes to the class canbe easily reflected in the
>> related SQL.
>
> But if all the classes need nearly the same SQL, it may make sense to
> abstract that out to a common location.That is what Serdar is trying
> to do. Duplication is also a bad smell.

Thats not what he said, he says he wants to collect SQL thats scattered
into one location. And his pseudo code has the classic procedural
case statement to select the right SQL depending on class. He is not
calling a single parameterised piece of SQL... Thats the bad smell.

If the SQL is common then the OO way to handle that would be
to write a mixin class called, say, Storable that accessed the real
instance attributes(like tablename). That could then be inherited by
all Storable objects. That way you get the common code and avoid
the case statement based on type.

PS. I know Kent knows about mixins, the explanation was for
anyone else who is intrested :-)

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list