Thursday, February 18, 2010

Overloading Properties with Visibility Modifiers

In C#, I keep running into instances where I would like to protect code blocks or have a decision for the code execution path based on a visibility modifier. Programming against an execution sequence based on the calling code location (visibility) could prove to be extremely useful and create safer, more readable code. I can find many instances were I program a single public property to act a certain way given the "state" of the object. This is very typical in shared libraries that are used both server and client side. An object that is transported and serialized can act differently based on it's location server or client side. There are plenty of other uses to overload a method with visibility, this is just one example.

Of course there would need to have an implicit notion of "next least visible" or "matching visibility" execution path. An internal calling sequence should be directed to an "internal property" if one exists. If it does not exist, the next least visible (but greater then the current) path should be chosen. It should also be possible to specify explicitly, at the call, which visibility path is intended. For example:

myObject.ID.public = 123;
myObject.ID.internal = 123;

The execution path for a property overloaded using a visibility modifier is a static (compile time) decision. The following code block is an example of an overloaded property in C#.

/* NOTE: THIS IS NOT LEGAL C#, causes property already defined error */

public int ID
{
get
{
return data.ID;
}
internal set
{
data.ID = value;
}
set // assumed public
{
modified.ID = value;
}
}

Thursday, January 14, 2010

iPhone Sync'd with Google Calendar

Syncing the iPhone with Google is really easy and allows the organization of contacts, calendars and email (of course). By simply adding your Gmail account as Exchange Server on the iPhone, the option of syncing is available. If you use Google Voice it is really nice to have the contacts synced immediately as soon as you enter them on either the iPhone or on the web. See http://www.google.com/mobile/sync/