Suppose we define the Customer object as follows:
<object name="Customer">
<property name="name" />
</object>
Based on this knowledge, our code generator emits the following snippet:
public void SaveCustomer(string name)
{
Customer customer = new Customer();
customer.Name = name;
customer.Save();
}
Since our application needs the Customer's name to be capitalized, we customize the code as follows. Let's name this version V1.
public void SaveCustomer(string name)
{
Customer customer = new Customer();
customer.Name = name.ToUpper();
customer.Save();
}
We later add an Address property to the Customer object:
<object name="Customer">
<property name="name" />
<property name="address" />
</object>
This time, our code generator emits the following snippet.
Let's name this version V2.
public void SaveCustomer(string name, string address)
{
Customer customer = new Customer();
customer.Name = name;
customer.Address = address;
customer.Save();
};
The following strategy highlights how to integrate the new code, while preserving the customizations that were made. This will be accomplished by merging the customized version V1 with the regenerated version V2.
The two following conflicts will be reported:
V1 public void SaveCustomer(string name)
V2 public void SaveCustomer(string name, string address)
V1 customer.Name = name.ToUpper();
V2 customer.Name = name;
Knowing that we are adding the Address property, the first conflict is easily resolved in favor of the regenerated V2. In contrast, the new property should not impact the Customer's name, so the second conflict is resolved in favor of the customized V1.
A diff between version V1 and the merged code will then confirm that the new code was correctly integrated:
- public void SaveCustomer(string name)
+ public void SaveCustomer(string name, string address)
= {
= Customer customer = new Customer();
= customer.Name = name.ToUpper();
+ customer.Address = address;
= customer.Save();
= }
Sunday, November 14, 2010
Subscribe to:
Comments (Atom)