Monday, August 17, 2009

Continue working with Command Line and a non generic refactor

I continue working on command line. The second part of day I did replace the code creation code of shapes to be a bit simpler and secondly was made for be prepared for future (for be possible to have tags marking for node in a transparent way).

In fact a lot of code was reduced, but the biggest advantage is that it setups some defaults also: the new node created will be auto-numbered (like: Line-1, Line-2) and it will be setup as visible by default.

So the typical code changes from:
var node = _document.Root.AddNewChild();
node.Update<StringInterpreter>().Value = AutoNumbering.GetNextIndex(FunctionNames.Rectangle);
var function = node.Update<FunctionInterpreter>();
function.Name = FunctionNames.Rectangle;
function.Dependency.Child(0).Point3D = v1;
function.Dependency.Child(1).Point3D = v2;
function.Dependency.Child(2).Point3D = v3;
node.Update<IntegerInterpreter>().Value = (int)OcafObjectVisibility.ToBeDisplayed;
function.Execute();

To:
var builder = new NodeBuilder(_document.Root, FunctionNames.Rectangle);
builder.Dependency.Child(0).Point3D = v1;
builder.Dependency.Child(1).Point3D = v2;
builder.Dependency.Child(2).Point3D = v3;
builder.ExecuteFunction();

Both code are really equivalent, the single difference is that NodeBuilder will do all the code internally for you like setting up visibility or the attached description string.

So enjoy using the new code

No comments: