#1882 Is there a alternative for Generics?

mase Wed 25 Apr 2012

All,

I'm trying to create a generic class/mixin Event that can be extended by a actual event types.

The idea is as follows:

const class Event 
{
  <actual source type> source
  Uuid ID := Uuid()

  ...
}

const class SystemEvent : Event 
{
  ...
}

Problem that I'm struggling with is the source of the Event. For one event type it is of type A, and for another event type it is of type B. Since generics are not supported within Fantom, I'm kind of wondering how this could be best done.

Kind of the same applies for the method by which the notification of events can be triggered:

mixin EventSource 
{

  abstract EventListener[] listeners := EventListener[,]

  Void notify(<event type> event)
  {
    // Go over list of event listeners and notify event occurred
  }

  Void addListener(EventListener listener)
  {
  }
}

mixin EventListener 
{
  Void eventOccurred(<event type> event) 
  {
  }  
}

brian Wed 25 Apr 2012

Without generics, Fantom works much like C# 1.0 or Java 1.4. Typically you just use Obj or the least common base class. The difference between Fantom and Java 1.4 is that Fantom has a lot more support for coercion of types that avoids most of the casting.

Login or Signup to reply.