tags:

views:

138

answers:

4

I have 3 different types of data: images, videos, and audio clips. Each one has an associated GPS point, so I have a base class as such:

public abstract class Data {
    public Latitude { get; set; }
    public Longitude { get; set; }
}

This is so I can plot everything on a map without worrying about what kind of data it is. However, I've been reading that POCO is not supposed be derived from anything except the base object class in C#. Is this true?

+4  A: 

No, many POCO objects have base classes.There is no rule saying they can't have or should have base classes. If it makes sense in your application then do it.

Chuck Conway
+1  A: 

I see nothing wrong with inheritance for plain old clr objects. In fact, inheritance is a driving factor as to why I like to use POCO objects instead things like Datasets.

Aaron Daniels
+1  A: 

Where did you read that? How would you build an object hierarchy if you were not allowed to derive from classes other than System.Object? (It goes without saying that System.Object will always be at the top of your class hierarchy in .NET)

0xA3
I read that here: http://www.subsonicproject.com/docs/Using_SimpleRepositoryUnder summary, it says: "The objects they create a free of base classes and exist on their own, as plain-old CLR objects (also known as POCOs)."
Daniel T.
I believe the 'a' is supposed to be 'are'.
Daniel T.
+1  A: 

When the word POCO is used, it's often to express the opposite of when you must inherit of a base class to use a frameork like some ORM tools requires:

MyClass : PersistableEntity (here PersistableEntity is a class to manage technical persistence in a ActiveRecord framework)

So you can't express inheritance in your class since you can only inherit from one class. If so you can use aggregation instead of inheritance.

So in your example, your class is POCO :)

Matthieu