[Mono-list] Is Objective-C support possible?
Robert Deviasse
rdeviasse@hotmail.com
Mon, 17 Sep 2001 09:36:21 -0400
I'm not sure if categories can be added to classes or objects so I'll go
through both cases:
I can think of two approaches, decentralized and centralized.
If you use the decentralized approach, you'd implement it this way:
----------------
If categories can only be added to objects, you can derive all Objective
C classes from:
interface ObjectiveCObject
{
public object __msgCall(string methodName, params object[]
methodParameters);
public object __addCategory(ObjectiveCCategory category);
public object __removeCategory(ObjectiveCCategory category);
};
Each class will need to implement the appropriate forwarding magic.
__addCategory and __removeCategory would add or remove a category
from the list of categories
__msgCall would use the category list to determine which method to
call.
NOTE: If categories only contain method calls, you can define
ObjectiveCCategory as being an array of delegates.
In that case, implementing __addCategory and __removeCategory would
simply add/remove to/from a list of delegates.
----------------
Now if categories can only be added to classes, you'd declare the
following
class ObjectiveCMetaClass
{
public object msgCall(object myself, string methodName, params object[]
methodParameters) { ... }
public object addCategory(ObjectiveCCategory category) { ... }
public object removeCategory(ObjectiveCCategory category) { ... }
};
Then, each objective C class needs to have a static member called:
ObjectiveCMetaClass __metaClass;
Methods and categories from each class could be accessed from this
member.
----------------
Alternately, you can go with a centralized approach. You'd define the
following class:
class ObjectiveCGeneralForwardingClass
{
public object msgCall(object registrant, object myself, string
methodName, params object[] methodParameters) { ... }
public object addCategory(object registrant, ObjectiveCCategory category)
{ ... }
public object removeCategory(object registrant, ObjectiveCCategory
category) { ... }
};
If categories need to be added to classes, the registrant argument above
would be the class. If categories can be added to objects, the registrant
would be the object itself. There would be only one
ObjectiveCGeneralForwardingClass singleton per assembly, but there's no harm
in defining more.
My gut tells me that most Objective C implementations use the decentralized
approach.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp