Can sub-classes initialize-instance modify base-classes slot *before* base's initialize-instance executes?

Can sub-classes initialize-instance modify base-classes slot *before* base's initialize-instance executes?

Post by Kenn » Sat, 11 Oct 2008 05:05:30


I wish you had proved that with repl output...oh, christ, you are not
talking about padding, you are talking about the storage. Which takes me
back to your use of "This" which in turn takes me back to high school
geometry and Mr. Wiseman who always said "There's no room for pronouns
in geometry, Mr. Tilton.

That One will be along shortly to recommend either a metaclass or
AspectL, I will recommend Cells which always does things In the Right
Order(tm). And happily saves you from having to write i-i methods, that
name is too long and I have carpal tunnel, dammit! I digress.

A humbler "gee, let's do everything with CLOS!" solution would be to use
an :around method to set up the storage slot, doing so /after/
call-next-method to get the desired effect.

But now we have the CLOS tail wagging the dog, which I am afraid is you.
What happens when things get more complicated and you run out of
stupid GF dispatch tricks? /Now/ we need That One. Or Cells.

Interestingly, Cells was invented precisely to solve a problem with
order of calculation -- one where slots needed the value of slots from
other instances as well as the same -- not to do reactive programming
(the handiest name for this particular pet trick). Reactive just fell
out of the tree, which was the second sign to me that Cells was way
cool. The first was how it trivially dispatched the daunting problem of
getting complex gui geometry calculated in the right order.

She was simply wrong. That breaks the usefulness of generic dispatch.

Do I tell you my problems? :)


1. Initializing slots based on other slot values in Common Lisp Object System class definitions

2. Initializing With a Base Class Instance

I'm probably being dense here. In the following situation:

class Base {
int x;
int y;

class Decendant : Base {
int z;

I need a function (constructor or whatever) in "Decendant" that will take a
"Base" and do a member-wise copy of "Base"'s members to itself. I know I
could just copy each base member, but I know there's got to be a better way.

I tried the following constructor in Decendant:

public Decendant(Base _base) : base(_base) {
z = 0;

The problem is that "Base" doesn't have a constructor that takes an instance
of itself. I'd prefer not to modify "Base", if possible.

I looked at MemberwiseClone, but that doesn't look like what I need.

Thanks in Advance!


3. converting base class instance to derived class instance

4. Initialising base class reference members from a derived class

5. Question regarding initializing base class object to derived class object,

6. Initializing base class portion of a derived class in a constructor

7. Problem when subclass instance changes base class instance variable

8. Can you create an instance of a subclass with an existing instance of the base class?

9. Creating a subclass instance from a base class instance

10. using base class instance in a derived class

11. Hiding Base Class Properites from derived class instance

12. REPOST:Hiding base class property from derived class instance

13. Simple Inheritance : Creating derived classes from instances of base class.

14. Convert instance of derived class to base class

15. Does a Base Class know it's instanced class?