A
Aaron Watters
A C# question about constructors/static methods and inheritance:
Please help me make my code simpler!
For fun and as an exercise I wrote somewhat classical B-tree
implementation
in C# which I later ported to java and Python for comparison.
[ See http://bplusdotnet.sourceforge.net/ for full details and code
]
The basic tree implementation has a number of subclasses which are
very
similar except for the types of certain data elements and the return
types of certain static methods. The only way I could think of to
implement these involved a lot of cutting and pasting. For example,
from hBplusTree.cs
public class hBplusTree : BplusTree
{
hBplusTreeBytes xtree;
public hBplusTree(hBplusTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
.....
public static new hBplusTree Initialize(string treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
hBplusTreeBytes tree = hBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId, nodesize, buffersize);
return new hBplusTree(tree);
}
public static new hBplusTree Initialize(string treefileName, string
blockfileName,
int PrefixLength, int CultureId)
{
hBplusTreeBytes tree = hBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId);
return new hBplusTree(tree);
}
.....
public static new hBplusTree ReOpen(System.IO.Stream treefile,
System.IO.Stream blockfile)
{
hBplusTreeBytes tree = hBplusTreeBytes.ReOpen(treefile, blockfile);
return new hBplusTree(tree);
}
public static new hBplusTree ReOpen(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes.ReOpen(treefileName,
blockfileName);
return new hBplusTree(tree);
}
public static new hBplusTree ReadOnly(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes.ReadOnly(treefileName,
blockfileName);
return new hBplusTree(tree);
}
.....
and from xBplusTree.cs
public class xBplusTree : BplusTree
{
xBplusTreeBytes xtree;
public xBplusTree(xBplusTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
.....
public static new xBplusTree Initialize(string treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
xBplusTreeBytes tree = xBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId,
nodesize, buffersize);
return new xBplusTree(tree);
}
public static new xBplusTree Initialize(string treefileName,
string blockfileName, int PrefixLength, int CultureId)
{
xBplusTreeBytes tree = xBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId);
return new xBplusTree(tree);
}
.....
public static new xBplusTree ReOpen(System.IO.Stream treefile,
System.IO.Stream blockfile)
{
xBplusTreeBytes tree = xBplusTreeBytes.ReOpen(treefile, blockfile);
return new xBplusTree(tree);
}
public static new xBplusTree ReOpen(string treefileName, string
blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes.ReOpen(treefileName,
blockfileName);
return new xBplusTree(tree);
}
public static new xBplusTree ReadOnly(string treefileName,
string blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes.ReadOnly(treefileName,
blockfileName);
return new xBplusTree(tree);
}
.....
(look familiar?)
Without going into great detail the Python implementation is much
simpler
(or at least shorter) than this due to Python's very relaxed type
system.
My question is: Is there a better way to do this? Please inform!
Thanks,
-- Aaron Watters
===
Let's not elect him in 2004 either.
Please help me make my code simpler!
For fun and as an exercise I wrote somewhat classical B-tree
implementation
in C# which I later ported to java and Python for comparison.
[ See http://bplusdotnet.sourceforge.net/ for full details and code
]
The basic tree implementation has a number of subclasses which are
very
similar except for the types of certain data elements and the return
types of certain static methods. The only way I could think of to
implement these involved a lot of cutting and pasting. For example,
from hBplusTree.cs
public class hBplusTree : BplusTree
{
hBplusTreeBytes xtree;
public hBplusTree(hBplusTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
.....
public static new hBplusTree Initialize(string treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
hBplusTreeBytes tree = hBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId, nodesize, buffersize);
return new hBplusTree(tree);
}
public static new hBplusTree Initialize(string treefileName, string
blockfileName,
int PrefixLength, int CultureId)
{
hBplusTreeBytes tree = hBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId);
return new hBplusTree(tree);
}
.....
public static new hBplusTree ReOpen(System.IO.Stream treefile,
System.IO.Stream blockfile)
{
hBplusTreeBytes tree = hBplusTreeBytes.ReOpen(treefile, blockfile);
return new hBplusTree(tree);
}
public static new hBplusTree ReOpen(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes.ReOpen(treefileName,
blockfileName);
return new hBplusTree(tree);
}
public static new hBplusTree ReadOnly(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes.ReadOnly(treefileName,
blockfileName);
return new hBplusTree(tree);
}
.....
and from xBplusTree.cs
public class xBplusTree : BplusTree
{
xBplusTreeBytes xtree;
public xBplusTree(xBplusTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
.....
public static new xBplusTree Initialize(string treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
xBplusTreeBytes tree = xBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId,
nodesize, buffersize);
return new xBplusTree(tree);
}
public static new xBplusTree Initialize(string treefileName,
string blockfileName, int PrefixLength, int CultureId)
{
xBplusTreeBytes tree = xBplusTreeBytes.Initialize(treefileName,
blockfileName, PrefixLength, CultureId);
return new xBplusTree(tree);
}
.....
public static new xBplusTree ReOpen(System.IO.Stream treefile,
System.IO.Stream blockfile)
{
xBplusTreeBytes tree = xBplusTreeBytes.ReOpen(treefile, blockfile);
return new xBplusTree(tree);
}
public static new xBplusTree ReOpen(string treefileName, string
blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes.ReOpen(treefileName,
blockfileName);
return new xBplusTree(tree);
}
public static new xBplusTree ReadOnly(string treefileName,
string blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes.ReadOnly(treefileName,
blockfileName);
return new xBplusTree(tree);
}
.....
(look familiar?)
Without going into great detail the Python implementation is much
simpler
(or at least shorter) than this due to Python's very relaxed type
system.
My question is: Is there a better way to do this? Please inform!
Thanks,
-- Aaron Watters
===
Let's not elect him in 2004 either.