What would you put in the ultimate Base Class?

by Dan Zambonini

Ignoring the fragility, performance and even architectural arguments associated with superclasses (I like to just put my fingers in my ears, repeat 'na na na' over and over, and pretend these problems don't exist), I'm fond of declaring a single base class that can be extended by almost every other class in an application. (For the sake of this question, I'm thinking of PHP4, so will ignore the loveliness of interfaces, and other functionality beyond my means.)



So, if you were to implement such a ubiquitous base class, what methods would you put it in? To begin with, I'd consider the following:





  • A save or persist method, which could record the current object data to a configurable location: database, disk, memory (e.g. memCache), or session (cookie). This would also require a set of methods that define the mapping of properties to database tables/fields, and relations between classes (e.g. compositions).

  • Conversely, a load method, based on a unique identifier or condition.

  • A getAsXml() method that returns an XML representation of the object (either as a string, or appended to a provided DOM Node). Actually, maybe this should just be an ultra-flexible export or getRepresentation type method, that can also return the object as HTML, CSV and other formats.




What else might be useful, for debugging, logging, portability or otherwise? What about useful abstract methods, maybe for comparing or merging?


7 Comments

bazzargh
2005-11-02 07:52:03
this feature...
...rumoured to be in Perl7:


public void DWIM();

thechairman
2005-11-02 08:37:23
Developer Feedback info
http://www.silicontide.com/index.php?path=view&message=NTI=
m0smith
2005-11-02 08:43:14
Funny you should ask
I was just thinking about this the other day. In Java at least, we spend a lot of code transforming the same data into different objects. One method requires a certain object or class while another method requires a different object or class, all for the same data.


A great thing would be to have a way to treat an object as another object, after the fact. Again in Java, applying an interface to an object at runtime. There would need to have some sort of mapping definition to tell how a method in the virtual interface maps to the instance of the object it is decorating.


Matt
http://www.ferociousflirting.com

putchavn
2005-11-07 22:58:36
Seek, Process and Give Feedback
I am exploring the possibility of using feedback for self-adaptation of software objects.


For this, a software object O Ref must have ability:
1 To Seek and Receive Feedback (FBin)from the objects to which O Ref gives its outputs,
2 To Process and adapt (adjust / modify) internal parameters / operations of O Ref, and
3 To Give Feedback (FBOut)to the objects which give inputs to O Ref.


The Base Class is the best place to incorporate the above features because every sub-class must have this generic ability. Dependig on the purpose and functionality of the Class and its sub-classes, 1, 2 and 3 above would be more specific and specialized.


With this feedback capability sub-classes and variants need not be explicitly defined / coded; they would evolve within specified limits. Class hierarchies can be comprehensive and yet be compact.

Roscopeco
2005-11-08 15:18:41
Ultimate base class?
I think Ruby already has the ultimate base class...


;)

withaj
2005-11-08 23:37:18
revisiting the thoughts
Since we are not taking the overheads in consideration, how about having only a xml export interface, you wont need anything else if you have only that.
Another interesting addition may be a url to the repository of the class, a default location where the class objects may be stored, this may be a open socket,a file, data base allocator handle (or whatever you guys call it).
In addition to that a class GUID (Globally Unique ID) might be of some help.
withaj
2005-11-09 22:16:52
Seek, Process and Give Feedback
Interesting, really. Putchavn's set of abilities prescribed for classes look like to do more with neural network cells than anything else. I think point 2 is more interesting than the rest, I had put some thought on this subject some time back and would certainly like to take this comment further, this may be a serious deviation from the original subject, but, so be it.


I would look at the self-adaption paradigm of classes in a diffrent view (point 2 in putchavn's comment). I look at versioning the classes when they need to be self adaptable. The ability of a class to be modified (after all adjustment is modification) at the run time, on the fly itself needs a lot to be done.


One way of looking at this ability of runtime modification of classes attributes and its methods is by means of interpretation of the methods. So if the object code of a class can be read and run at the run time, the code can be easily be modified to change the state of a class in a diffrent manner. Please note that this ease of mofification is relative to ease of modification of a class that is compiled, linked and run.


Putchavn's point 2 thus tells us that there needs be lot -- like the ability of a class to expose the various methods at the run time, the ability of the class to express how each method will change the state of the class (this would be more in context of a self learning applicaion not implimenting neural n/w), ability of a class to refer to other classes, ability to discard a broken refrence (cause the class to which it might be refering for a purpose may have changed) and the ability of a class to relink a broken refrence to some other class in the pool (or should we say knowlede base ) depending on how that class changes its state (ie the behaviour of the class).


These will be a minimum for a super base class to impliment should putchavn's point 2 be implimentd.