473,491 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

constructors/static methods and inheritance query

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.
Nov 16 '05 #1
3 1732
Aaron,

I am kind of curious why so much of these members are static. I mean,
most of these members act on an instance, and it defeats the whole purpose
of OO to have it in this manner.

If you need the methods to return specific sub types, then you will have
to create a specialized instance for each type. This sucks, I know, but
it's the only way to do it in .NET 1.1 and before.

However, in 2.0, you will be able to define this as a generic type, and
have it perform operations and return that type from methods, when you
declare an instance of that type.

Also, as a side note, you have a tremendous number of naming violations
(type names, member names, parameter names, mostly casing errors) on your
publically exposed members. I would recommend adhering to the naming
convention for the .NET framework. It just makes it easier all around for
everyone IMO.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Aaron Watters" <aa***************@yahoo.com> wrote in message
news:e1**************************@posting.google.c om...
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.

Nov 16 '05 #2
Aaron,

I am kind of curious why so much of these members are static. I mean,
most of these members act on an instance, and it defeats the whole purpose
of OO to have it in this manner.

If you need the methods to return specific sub types, then you will have
to create a specialized instance for each type. This sucks, I know, but
it's the only way to do it in .NET 1.1 and before.

However, in 2.0, you will be able to define this as a generic type, and
have it perform operations and return that type from methods, when you
declare an instance of that type.

Also, as a side note, you have a tremendous number of naming violations
(type names, member names, parameter names, mostly casing errors) on your
publically exposed members. I would recommend adhering to the naming
convention for the .NET framework. It just makes it easier all around for
everyone IMO.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Aaron Watters" <aa***************@yahoo.com> wrote in message
news:e1**************************@posting.google.c om...
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.

Nov 16 '05 #3
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<On**************@TK2MSFTNGP15.phx.gbl>...
Aaron,

I am kind of curious why so much of these members are static. I mean,
most of these members act on an instance, and it defeats the whole purpose
of OO to have it in this manner.
Hardly. I'm just giving different names to different types of
constructors rather than overloading the standard constructor
20 different ways.
If you need the methods to return specific sub types, then you will have
to create a specialized instance for each type. This sucks, I know, but
it's the only way to do it in .NET 1.1 and before.

However, in 2.0, you will be able to define this as a generic type, and
have it perform operations and return that type from methods, when you
declare an instance of that type.
So I can't improve the code yet... bummer.
Also, as a side note, you have a tremendous number of naming violations
....


yes yes. Thanks for the response! -- Aaron Watters

===
Han: So whaddya think kid -- a princess and a guy like me...?
Luke: No.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
21366
by: Rajesh Garg | last post by:
Can we have private constructors and destructors? IF yes what is the use of such constructors or destructors.....in the sense where can these be implemented in a system................. I have...
3
18802
by: Amit | last post by:
is there anything like static constructors or destructors in C++ ? if yes, how to implement it? Thanks, Amit.
7
1865
by: Sunny | last post by:
Hi all, According C# Language Specification : 10.11 Static constructors: The static constructor for a class executes at most once in a given application domain. The execution of a static...
8
2329
by: Pent | last post by:
Hi All, Why is this code valid? How can the static ctor be used? It doesn't act as class ctor at all. struct A { static A() { } }
0
282
by: Aaron Watters | last post by:
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...
10
1203
by: Kevin Buchan | last post by:
I searched the news group and could not find an answer to this question, so I'll go ahead and post it. Let's say I have a class A with a couple different constructors... nothin' special. Now,...
68
3444
by: Peter Morris [Droopy eyes software] | last post by:
I have an object persistence framework I have written, this framework expects every object to descend ultimately from PersistentObject and to have a constructor (ObjectSpace objectSpace) so that...
4
1607
by: Adam | last post by:
Okay, so I know this will come off as a stupid question...but I am going to ask it anyways... I know you are not allowed to have constructors defined in an interface, but why not? I really...
7
16523
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.