[Grace-core] Revising factory inheritance
James Noble
kjx at ecs.vuw.ac.nz
Sun Mar 17 23:21:43 PDT 2013
A few comments on Michael's email ...
> I am increasingly leaning towards the "factory method"/"satan"
calling it "satanic" really wasn't that clever of me...
The key idea of Michael's email is, I think:
> method someFactory {
> object {
> inherits someOtherFactory(1,2)
> }
> }
basically passing along calls to factory methods
as part of object constructors that don't add anything
else --- all they do is chain to another constructor.
In other words - the special semantics to ensure
the "self" of the new object is preserved
> This definition gives, in essence, classical inheritance semantics
So (I think - more or less) what we *have* decided - in that all
the proposals we're considering support this - is "classical"
inheritance semantic for class declarations basically with the
current syntax. Code is executed top-down from superclasses
to subclasses with "self" bound to the finally constructed object:
access to uninitialised variables -as always in Grace - raises at
least a dynamic exception.
> How can that resolve our other problems? In particular, Andrew wants
> to inherit from arbitrary pre-existing objects, patterns want to
> inherit from booleans, and dialects at least want to include other
> modules in themselves.
Not sure andrew wants to do this any more...
> We can achieve that by defining a method which I'll call delegate(x : Object).
so this is an alternative to just inheriting from a clone, I think,
with slightly different semantics...
> We could also have another method, concatenate, giving concatenation
> semantics (copying the object into the new one) if those are desired.
this is the same as cloning the parent?
> Crucially, these methods are not part of the semantics of the language
> or of inheritance - they're just methods, whose implementation is
> encapsulated.
right - and they're not really key to the factory method proposal.
> I think this works. I think we should pick this and move ahead with it.
well it's clear we'll need to talk more now that Andrew's also sent something.
I still think the OOPSLA submission should be the first priority.
J
From earlier email
Subject: [Grace-core] [less important] Classical Inheritance vs Delegation
Date: 9 March 2013 7:54:34 PM NZDT
Some other notes from today's discussion - Kim on "classical inheritance"
A class definition is a template for instances
- instance variables
- method suite
- some kind of parameterised initialisation code
Single Inheritance:
A subclass definition includes all of the above class definition
- along with a single superclass
- its method suite may override the superclass's methods
- initialisation code in the superclass runs before the code for the subclass
with "self" bound to the whole new object
- initialisation code can make self-calls, these should have the same semantics
as normal method calls
Classes do not have to be objects --- they can be separate, static, non-first class.
BUT: classes as objects in so far as they are factories - that "new" is a standard
method call - is important and good.
More information about the Grace-core
mailing list