Traceable Layer Formatting Objects

While most basic type of data are easily converted to text output, you should add this ability to Traceable Layer version of any classes you are using. If you don't provide some type of output formatting then the object type will be used. For example, we pass an object into a function, we might see something like this: <ClassName.FunctionCall result="something"> <parameter>FunctionalLayer.CustomersData</parameter> <ClassName.FunctionCall>

We might be able to infer which instance was passed into function, but that is not guaranteed. What is better to do is to construct specific output that we want to place into the trace data. For example, we have a the eponymous CustomerData class: namespace FunctionalLayer.Customers { public class CustomerData { public virtual string CustomerId { get; set; } public virtual string LastName { get; set; } public virtual string FirstName { get; set; } ... } }

In the Traceable Layer class, we override the ToString() function to output the information we want: namespace TraceableLayer.Customers { public class CustomerData : FunctionalLayer.Customers { ... public override string ToString() { return base.LastName + "," + base.FirstName + "(" + base.CustomerId + ")"; } } }

We then have the trace code apply ToString() to the object. If the CustomerData is passed into a function as a parameter, we will get output that looks like this: <ClassName.FunctionCall result="something"> <parameter>Smith,John(C123-723J6Q)</parameter> ... <ClassName.FunctionCall>

Design Note: the ToString() function calls the base object to get the values that are returned. This is necessary. If the code looked like public override ToString() { return LastName + "," + FirstName + "(" + CustomerId + ")"; } then the output would be polluted with extra lines; and would look like <ClassName.FunctionCall result="something"> <CustomerData.LastName>Smith</CustomerData.LastName> <CustomerData.FirstName>Smith</CustomerData.FirstName> <CustomerData.CustomerId>Smith</CustomerData.CustomerId> <parameter>Smith,John(C123-723J6Q)</parameter> ... <ClassName.FunctionCall> Also note that I included both the CustomerId and the name of the customer in the output. While the customer's name is very easy for a person to read, the CustomerId makes sure we have a unique number for each customer. This can be very important in the event that we are looking at a data set where multiple people have the same name.

Some might argue that we only need the CustomerId in the output. However, most people do not naturally remember long strings of arbitrary alphanumeric sequences. Anytime we have to stop and look at the data, and mentally translate it, we slow down out analysis, and introduce a strong potential for a mistake to be introduced. Always remember: the computer is supposed to be doing the work for you, not you doing the work for the computer.

Next: Tracer