Site Sponsors:
Generic Object Placeholders in Templates 
I am reminded that it is good to remember that we can use templates to take advantage of "isa:" In C# and Java specifically, since all classes are reference types (object pointers), the universal object-placeholder is Object. From a template's point of view, Everything 'isan' Object.

What does having a universal Object for absolutely all classes, mean? -Well, much like using "void *" in C/C++, Java and C#'s Object offers us all of that polymorphic goodness, as well as some sophisticated base operations.

To demonstrate the former, given the following template + interface combination:


public interface OmniAdapter<T> {
// Adapter: Convert one object, to another
Object xForm(T ref);
}


-We can support a simple child 'Object'-conversion:


public class Event3 extends Day2
implements OmniAdapter<Day2> {

public MyNewClass xForm(Day2 ref)
{
return new MyNewClass(ref);
}
}


What is interesting to keep in-mind here is that, because MyNewClass is-an Object, that we can xForm one type, to another. -Even if MyNewClass is only used by a single, solitary function - as long as the compiler can find it - then we can return it.

Enjoy,

-Rn


[ add comment ] ( 1917 views )   |  permalink

<<First <Back | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | Next> Last>>