tags:

views:

46

answers:

1

Thinking about entity classes, what could I do to keep my source code with a few number of lines of code, when the entity starts to getting bigger?

The entity in this case have attributes, methods (already optimized to be small), lazy-loading code for reference to another objects, and repository objects to allow lazy-loading.

I'm not thinking about creating a class for the logic executed in this entity, because it seems to be breaking OO principles.

Actually, I have an entity with 15 attributes, and nearly 200 lines of code. Is splitting the class into two entities the only thing do to here? What else could be done here?

+1  A: 

Just make your "entity" a simple poco and have a service layer, or the like, perform the rest of your logic. To me this is more of a design question, so i would look at the design and decide if you can live with the ever growing entity and if not then think about make them a poco.

Your poco classes should look something like this... and just apply the desired pattern to this ie: a Repository/ service layer.

public class Customer
    {
        string _CustomerID;
        string _ContactName;
        string _City;
        List<Order> _Orders;

        public string CustomerID
        {
            get { return _CustomerID; }
            set { _CustomerID = value; }
        }

        public string ContactName
        {
            get { return _ContactName; }
            set { _ContactName = value; }
        }

        public string City
        {
            get { return _City; }
            set { _City = value; }
        }

        public List<Order> Orders
        {
            get { return _Orders; }
            set { _Orders = value; }
        }
    }
YetAnotherDeveloper
If you are using .net 3 you can shorten the properties to bepublic string CustomerID {get;set;}
lfoust
Sure can, but the point is to make the entity simple and a dumb container with the business logic and data access code elsewhere.
YetAnotherDeveloper