I agree with the sentiments of other posters that sub-classing the types in the SharePoint object model is a bad idea. My biggest reasons for doing so are:
- the way that SharePoint intrinsically disposes objects based on the context they were created in.
- you'd be creating a type hierarchy based on subtypes that aren't under your control.
The dispose issue is probably the biggest deterrent.
Inheritance isn't always the best solution in sticking to OO principles. An object hierarchy has it's downsides too when it comes to maintenance.
It sounds like you've already explored encapsulation which is a perfectly valid OO approach and would be preferred over inheritance (in my opinion):
public class Order {
private SPListItem listItem;
...
public Order(SPListItem listItem) {
this.listItem = listItem;
}
...
public int ItemName {
get { return listItem["Title"] as string }
set { listItem["Title"] = value; }
}
...
}
One problem with these approaches (inheritance and encapsulation) is that they couple your objects to the underlying data store (SharePoint in this case). This may or may not be a bad thing depending on what you're trying to design.
An alternative approach is keeping your code separate from the underlying store and using a repository to handle getting and updating objects in the repository. At least any coupling to SharePoint can be handled by a single repository type, and you can put an interface around it to allow you to use other repositories (either for future scenarios or for testing).
It all depends on your use case and how much your code and platform may change in the future.
One nice, lightweight approach is in Chris O'Brien's blog (Simple data access pattern for SharePoint lists). If your needs match up with his it's a practical way to go.