An Opinion blog

My Links

Story Categories

Archives

Post Categories

Image Galleries

Login


Remember

Disclaimer

This site is operated by Mike Deem. The opinions expressed here are mine. They are not necessarily my employer's or anybody else's.

WinFS and Interfaces

Richard Tallent asks in addition to a type hierarchy, will there be inherent support for Interfaces instead of classes? This is a really interesting question and answering it gives me an opportunity talk about the third major type hierarchy in WinFS: extensions (the other two are items and relationships).

In CLR, interfaces are typically used to describe a behavioral contract. Since a class can implement multiple interfaces (but can be derived from only one class), interfaces allow for a kind of extensibility over time. An existing class can implement a new interface when adding new behavior allowing it to play a new role in a system.

WinFS schemas are primarily about describing data that will be stored, not behavior, so interfaces don't really fit into the WinFS data model. However, the API classes generated from the schema can implement behavior and can leverage interfaces just like any other CLR class.

But WinFS items do provide for an extensibility mechanism. In a schema I can defined an extension type with properties. Instances of extensions can be attached to item instances. For example, if I wanted to add an “hair color“ property to the standard Person item type I could define an extension as follows:

<ExtensionType Name=”PhysicalDescription” BaseType=”System.Storage.Extension”>
  <Property Name=“HairColor“ Type=“String“ Size=“50“/>
</ExtensionType>

I can add an instance of this extension to a Person item as follows:

ItemContext ic = ItemContext.Open();
Person p = Person.FindItemById( id );
PhysicalDescription d = new PhysicalDescription();
d.HairColor = “Brown”;
p.Extensions.Add( d );
ic.SaveChanges();

I can find all Person items representing people with brown hair using the code:

ItemContext ic = ItemContext.Open();
FindResult result = Person.FindAll(
  “Extensions.Case(PhysicalDescription).HairColor='Brown'“);

foreach( Person p in result ) {
  Console.WriteLine( p.DisplayName );
}

posted on Wednesday, November 19, 2003 9:52 PM

Feedback
Post a Comment

Remember Me?