I think you are missing some of the key points. Like why?
In true practice, they are separated (specifically in the way you have shown) because the logic exists and is running on different systems.
For example, a user may be running a client application (presentation layer and business logic layer) which calls some services (data access layer), which in turn query a Database (Data layer).
By designing it using N-Tier, one can build an application and deploy quickly using separation of concerns. If the logic is not separated, it is difficult and possibly dangerous as parts of the system will end up exposed that should not be (e.g. no user should be able to directly access your DB).
Also for easy extension, one should use Interfaces and contracts. For example, the
Person
object should be as follows:
[DataContract]
public class Person
{
[DataMember]
public string Firstname {get;set;}
[DataMember]
public string Lastname {get;set;}
[DataMember]
public int Age {get;set;}
}
This allows the object type to be built in the Access Layer and then serialized to the client.
As for using interfaces, it is more optimal because you need only expose the interface where it is used but can change the innerworkings, however is appropriate. Once you get into injection, you are going beyond "beginner", but the precedence should still be set.
Interfaces can be exposed as a single project library.
public interface IPerson
{
string FirstName {get; set;}
string LastName {get; set;}
int Age {get;}
void HaveBirthday();
}
public interface IDrinker
{
bool IsIntoxicated {get;}
}
public interface IReceiveToys
{
bool IsPlayingWithNewToys {get; }
}
The actual contracts need to use the appropriate attributes to serialize the data from the service calls.
[DataContract]
public class Adult : IPerson, IDrinker
{
[DataMember]
public string Firstname {get;set;}
[DataMember]
public string Lastname {get;set;}
[DataMember]
public int Age {get; private set;}
public bool IsIntoxicated {get; private set;}
public void HaveBirthday()
{
Age++;
Celebrate();
}
private void Celebrate()
{
IsIntoxicated = true;
}
}
[DataContract]
public class Child : IPerson, IReceiveToys
{
[DataMember]
public string Firstname {get;set;}
[DataMember]
public string Lastname {get;set;}
[DataMember]
public int Age {get; private set;}
public bool IsPlayingWithNewToys {get; private set;}
public List<IGift> Gifts {get; set;}
public void HaveBirthday()
{
Age++;
UnWrapGifts();
}
private void UnWrapGifts()
{
if(Gifts.Count > 0)
IsPlayeWithNewToys = true;
}
}
[EDIT]HTML Tags slightly off.