473,756 Members | 3,973 Online
Bytes | Software Development & Data Engineering Community
+ 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(hBpl usTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
.....
public static new hBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
hBplusTreeBytes tree = hBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId, nodesize, buffersize);
return new hBplusTree(tree );
}
public static new hBplusTree Initialize(stri ng treefileName, string
blockfileName,
int PrefixLength, int CultureId)
{
hBplusTreeBytes tree = hBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId);
return new hBplusTree(tree );
}
.....
public static new hBplusTree ReOpen(System.I O.Stream treefile,
System.IO.Strea m blockfile)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReOpen(treefil e, blockfile);
return new hBplusTree(tree );
}
public static new hBplusTree ReOpen(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReOpen(treefil eName,
blockfileName);
return new hBplusTree(tree );
}
public static new hBplusTree ReadOnly(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReadOnly(treef ileName,
blockfileName);
return new hBplusTree(tree );
}
.....

and from xBplusTree.cs

public class xBplusTree : BplusTree
{
xBplusTreeBytes xtree;
public xBplusTree(xBpl usTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
.....
public static new xBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
xBplusTreeBytes tree = xBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId,
nodesize, buffersize);
return new xBplusTree(tree );
}
public static new xBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId)
{
xBplusTreeBytes tree = xBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId);
return new xBplusTree(tree );
}
.....
public static new xBplusTree ReOpen(System.I O.Stream treefile,
System.IO.Strea m blockfile)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReOpen(treefil e, blockfile);
return new xBplusTree(tree );
}
public static new xBplusTree ReOpen(string treefileName, string
blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReOpen(treefil eName,
blockfileName);
return new xBplusTree(tree );
}
public static new xBplusTree ReadOnly(string treefileName,
string blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReadOnly(treef ileName,
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 1750
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.co m

"Aaron Watters" <aa************ ***@yahoo.com> wrote in message
news:e1******** *************** ***@posting.goo gle.com...
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(hBpl usTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
....
public static new hBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
hBplusTreeBytes tree = hBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId, nodesize, buffersize);
return new hBplusTree(tree );
}
public static new hBplusTree Initialize(stri ng treefileName, string
blockfileName,
int PrefixLength, int CultureId)
{
hBplusTreeBytes tree = hBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId);
return new hBplusTree(tree );
}
....
public static new hBplusTree ReOpen(System.I O.Stream treefile,
System.IO.Strea m blockfile)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReOpen(treefil e, blockfile);
return new hBplusTree(tree );
}
public static new hBplusTree ReOpen(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReOpen(treefil eName,
blockfileName);
return new hBplusTree(tree );
}
public static new hBplusTree ReadOnly(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReadOnly(treef ileName,
blockfileName);
return new hBplusTree(tree );
}
....

and from xBplusTree.cs

public class xBplusTree : BplusTree
{
xBplusTreeBytes xtree;
public xBplusTree(xBpl usTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
....
public static new xBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
xBplusTreeBytes tree = xBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId,
nodesize, buffersize);
return new xBplusTree(tree );
}
public static new xBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId)
{
xBplusTreeBytes tree = xBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId);
return new xBplusTree(tree );
}
....
public static new xBplusTree ReOpen(System.I O.Stream treefile,
System.IO.Strea m blockfile)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReOpen(treefil e, blockfile);
return new xBplusTree(tree );
}
public static new xBplusTree ReOpen(string treefileName, string
blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReOpen(treefil eName,
blockfileName);
return new xBplusTree(tree );
}
public static new xBplusTree ReadOnly(string treefileName,
string blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReadOnly(treef ileName,
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.co m

"Aaron Watters" <aa************ ***@yahoo.com> wrote in message
news:e1******** *************** ***@posting.goo gle.com...
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(hBpl usTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
....
public static new hBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
hBplusTreeBytes tree = hBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId, nodesize, buffersize);
return new hBplusTree(tree );
}
public static new hBplusTree Initialize(stri ng treefileName, string
blockfileName,
int PrefixLength, int CultureId)
{
hBplusTreeBytes tree = hBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId);
return new hBplusTree(tree );
}
....
public static new hBplusTree ReOpen(System.I O.Stream treefile,
System.IO.Strea m blockfile)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReOpen(treefil e, blockfile);
return new hBplusTree(tree );
}
public static new hBplusTree ReOpen(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReOpen(treefil eName,
blockfileName);
return new hBplusTree(tree );
}
public static new hBplusTree ReadOnly(string treefileName, string
blockfileName)
{
hBplusTreeBytes tree = hBplusTreeBytes .ReadOnly(treef ileName,
blockfileName);
return new hBplusTree(tree );
}
....

and from xBplusTree.cs

public class xBplusTree : BplusTree
{
xBplusTreeBytes xtree;
public xBplusTree(xBpl usTreeBytes tree) : base(tree)
{
this.xtree = tree;
}
....
public static new xBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
{
xBplusTreeBytes tree = xBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId,
nodesize, buffersize);
return new xBplusTree(tree );
}
public static new xBplusTree Initialize(stri ng treefileName,
string blockfileName, int PrefixLength, int CultureId)
{
xBplusTreeBytes tree = xBplusTreeBytes .Initialize(tre efileName,
blockfileName, PrefixLength, CultureId);
return new xBplusTree(tree );
}
....
public static new xBplusTree ReOpen(System.I O.Stream treefile,
System.IO.Strea m blockfile)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReOpen(treefil e, blockfile);
return new xBplusTree(tree );
}
public static new xBplusTree ReOpen(string treefileName, string
blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReOpen(treefil eName,
blockfileName);
return new xBplusTree(tree );
}
public static new xBplusTree ReadOnly(string treefileName,
string blockfileName)
{
xBplusTreeBytes tree = xBplusTreeBytes .ReadOnly(treef ileName,
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.c om> wrote in message news:<On******* *******@TK2MSFT NGP15.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
21391
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 an idea that we can have private constructors and destructors but am not able to find a situation where they can be used... Regards RVG rajeshgarg@opussoft.com
3
18815
by: Amit | last post by:
is there anything like static constructors or destructors in C++ ? if yes, how to implement it? Thanks, Amit.
7
1877
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 constructor is triggered by the first of the following events to occur within an application domain: - An instance of the class is created.
8
2347
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 later ported to java and Python for comparison. http://bplusdotnet.sourceforge.net/ for full details and code ]
10
1227
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, let's say that I have class B that inherits from A. B automagically gets all of the properties and methods of A, but I cannot leverage any of A's contructors without redefining them on B and delegating. I'm sure that there is a very good reason...
68
3533
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 objects may be recreated. PersistentObject's constructor will do something like this this.ObjectSpace = objectSpace; objectSpace.RegisterObjectCreation(this); The object space will record a reference to this new object + do something
4
1620
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 dont need ways/design patterns around this issue. What I want to know is why the CLR does not allow this. Regards,
7
16571
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 called "Point" which would have two values "x" and "y". Now, let's say if it were the Java version, I would want two constructors: one that accept two numbers, the other accepts a string:
0
9455
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10031
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9869
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9838
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.