473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1728
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
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
by: Amit | last post by:
is there anything like static constructors or destructors in C++ ? if yes, how to implement it? Thanks, Amit.
7
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.