Why are interfaces so restrictive?
Jarrett Billingsley
kb3ctd2 at yahoo.com
Fri Mar 17 17:47:16 PST 2006
"BCS" <BCS_member at pathlink.com> wrote in message
news:dvfm45$1j5f$3 at digitaldaemon.com...
> why not let a struct implement an interface
Because that would complicate structs, something that I think Walter is not
willing to do.
> or even let a function define an interface literal..
You could define an anonymous class literal which implemented that
interface.
class Item
{
}
interface Database
{
Item SearchForItem(char[]);
bool AddItem(char[], Item);
bool RemoveItem(char[]);
}
void DatabaseUI(Database deebs)
{
}
void Foo()
{
DatabaseUI(new class Database
{
Item[char[]] bar;
Item SearchForItem(char[] n)
{
if(n in bar)
return bar[n];
throw new Error("blah!");
}
bool AddItem(char[] n, Item i)
{
if(n in bar)
throw new Error("blah!");
bar[n] = i;
return true;
}
bool RemoveItem(char[] n)
{
if(n in bar)
{
bar.remove(n);
return true;
}
throw new Error("blah!");
}
});
}
void main()
{
}
More information about the Digitalmars-d
mailing list