Jump to content
Posted 10 May 2004 - 10:22 PM
Posted 10 May 2004 - 10:57 PM
string myObject = "CMyClass";- in C++ or the like? Reflection is what would be used to do this. Unfortunately raw C++ doesn't have a reflection library, but languages like Java and C# (and other .NET languages) do.
IArray, which has some common array methods: addition, removal, and traditional index access via the  operator. Now, let's say you have two classes
CArray(actually implementations now) and
CLinkedListwhich both implement
IArray. The idea is that the client can use
IArraywithout worrying how it's implemented. As you can see, one classes implements it uses arrays, however another implements it using linked lists. It doesn't matter how it's implemented though, as long as the interface works the way it's supposed to. Thus the linked list class has to implement the  operator whether it likes it or not if it wants to implement the IArray interface.
IComparable, which has a CompareTo function. However, once it's implemented, you have access to this great utility function. It doesn't really care what the object is, as long as it has the CompareTo function to work with.
IEnumberablemeans that your class can be enumerated, or iterated over. Implement this interface, and you can use the
foreachmechanism in C#. Also cool. In closing, interfaces are just that - they allow you to interface "generically" with client code, regardless of implementation. As long as your implementation actually works, that is.
Posted 11 May 2004 - 03:37 AM
Original post by Toolmaker
I can''t seem to grasp the general ideas behind Attributes
Can someone point me out what it is, what the use of it is and the finer details? I read "A Programmer''s Introduction to C#" but I can''t really grasp the concept from there.
The same goes for interfaces
What''s the idea behind those?
Posted 11 May 2004 - 10:45 AM
Posted 11 May 2004 - 01:27 PM
Original post by Toolmaker
So, interfaces are more or less abstract classes(Or in C++ speak, pure virtual classes) which forces the implementing class to override them.
One thing I don''t get about it, why just don''t use abstract classes in this case? Or am I getting it wrong here? Or do you use interfaces as a generic interface? E.g, some functions wants a reference of ICustomArray for handling(For instance, foreach) data in it. Wether ICustomArray is hardcoded, linked listed, stored inside a database or uses the surface of the moon to get it''s data isn''t of importance. All have to do it implement the interface, create an instance of CMyClass and cast it back to ICustomArray and then pass this to the function? But doesn''t a base class work there too?
Posted 11 May 2004 - 01:34 PM