assign responsibility

  • Thread starter Thread starter Marty M
  • Start date Start date
M

Marty M

public abstract class Animal
{
private string Id;
}

public class Dog : Animal
{
//properties/fields for Dog
public void Add()
{logic to persist to database}

}

We'd like Dog to persist himself to database. We'd like classes
derived from Animal to always have a GUID in Id. But derived classes
should not worry about that, they don't have to know about the Id.
How do we do this while making Dog responsible to add himself? We
don't want to use Animal constructor because Id is only used for
Insert. Ideas? thanks! Marty
 
Hi Marty,

Please stay in the same thread and do not message twice, I saw Peter did
answer your previous question but for the same someone else had started to
evaluate your question again.

Cor
 
That is my mistake, I apologize. I posted from work, did not see my post in
the group and thought that the post did not work properly. So I posted
again at home. I should let some time pass before I assume there was a
problem with the original post. Thanks for the reminder!
 
Back
Top