Topic: Defined signatures: Forked from: Proposal for Interfaces (version 3.0)
Author: hattons@globalsymmetry.com ("Steven T. Hatton")
Date: Sat, 24 Apr 2004 17:41:27 +0000 (UTC) Raw View
christopher diggins wrote:
> ""Steven T. Hatton"" <hattons@globalsymmetry.com> wrote in message
>> Could the same thing be accomplished simply by having the compiler
>> compare the signature of an implementing class to that of an interface
>> without
>> actually creating any extra runtime residue? That is, treat the
>> interface
>> as a contract that the compiler verifies for all implementing classes.
>> As long as conformance is verified, no matter if it's through
>> inheritance, hiding, or local definition, the interface is considered
>> implemented, and the code is compiled as if there were no interface.
>
> I believe this is what I do, I don't see how that is different from the
> proposal.
I believe what I was suggesting is a meta-abstraction. IOW, the mechanism I
was proposing would not have any actual residue in the object code or
executable. It would be a purely compile-time feature. It could be
understood as a user-defined signature check. For the sake of discussion
I'll call it a zero-mass interface. For example one might define such an
interface with the following statement:
// works for functions or classes
signature int zFunct(const int& arg1, const int& arg2);
The programmer would then use zfunct to force a check on a member function.
For example:
class MyClass{
zfunct int myFunct(const int& marg1, const int& marg2); //will compile
zfunct int myFunct(const nonInt& no_go, const int& marg2); //won't compile
}
Or for a class:
signature class zClassSig{
int zFunctA(const int& marg1, const int& marg2);
int zFunctB(const someClass& some_obj, const int& marg2);
}
/* compiles */
class zClass{
int zFunctA(const int& zarg1, const int& zarg2);
int zFunctB(const someClass& some_zobj, const int& zarg2);
}
/* doesn't compile */
class zClass{
int zFunctA(const int& zarg1, const int& zarg2);
}
This idea seems so simple and obvious that I feel there must be something
worng with it that I'm not seeing. Or perhaps something already does this,
and I'm not perceiving it. I'm just presenting it to the newsgroup because
it may actually have some merit.
There seem to be times when people whant to assert that a collection of
class templates exhibit certain features, but inheritance fails to support
the design. Perhaps the ability to literally define a signature would
provide a more deterministic means of enforcing conformance to the
conceptual abstract interface.
--
STH
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]