Entity Aggregation is to group distributed redundant data from different repository across enterprise into one entity.
I translate the concept into a sample code just for the purpose of demonstration. Bear in mind that many more functionalities are required to sastify the actual definition of this pattern.
1. Repository1 and Repository2 classes are created just for showing the concept. In reality, data should come from database, xml, flat file and other storage mechanisms.
2. EntityAggregation class combines data from Repository1 and Repository2 into one unit for transporting across the wire in the real world.
using System;
namespace Test
{
class Repository1
{
private string _fullname;
public string FullName
{
get { return _fullname; }
set { _fullname = value; }
}
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
public Repository1(string FullName, int Age)
{
this._fullname = FullName;
this._age = Age;
}
}
class Repository2
{
private string _fullname;
public string FullName
{
get { return _fullname; }
set { _fullname = value; }
}
private string _phone;
public string Phone
{
get { return _phone; }
set { _phone = value; }
}
public Repository2(string FullName, string Phone)
{
this._fullname = FullName;
this._phone = Phone;
}
}
public class EntityAggregation
{
private string _fullname;
public string FullName
{
get { return _fullname; }
set { _fullname = value; }
}
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
private string _phone;
public string Phone
{
get { return _phone; }
set { _phone = value; }
}
public EntityAggregation(string FullName, int Age, string Phone)
{
this._fullname = FullName;
this._age = Age;
this._phone = Phone;
}
}
public class BusinessProcess
{
public EntityAggregation GetData()
{
Repository1 r1 = new Repository1("Mei Lin", 35);
Repository2 r2 = new Repository2("Mei Lin", "1112223333");
return new EntityAggregation(r1.FullName, r1.Age, r2.Phone);
}
}
public class Test
{
public static void Main(string[] args)
{
BusinessProcess bp = new BusinessProcess();
EntityAggregation ea = bp.GetData();
Console.WriteLine("FullName {0} Age {1} Phone {2}",
ea.FullName, ea.Age, ea.Phone);
}
}
}
Love to hear your ideas and do share your experience about this pattern.
Have fun