473,881 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to better understand class design and types

I know in C++ you can create class templates so the data type can be defined
during the declaration of an instance of a class. I was trying to do
something like that for a VB.NET class cut am not really sure where to
start.

Here is an example for a simple DataArray class definition that sets up an
array used for numerical data and adds some additional functionality to the
array. The overloaded new methods work okay, although I'm not sure if it's
the right way to go about doing this, but for the other methods do I have to
write an overloaded method for each data type, or can I set these up to
identify the type of array that was created for this instance of the class?

Public Class DataArray
Public Data As Array
Public Sub New(ByVal dt As Array)
Data = dt
End Sub

Public Sub New(ByVal Size As Integer, ByVal DataType As Type)
Data = Array.CreateIns tance(DataType, Size)
End Sub

Public Function Max() As Double
' find maximum value of the area
Dim sortedData As Array
sortedData = Array.CreateIns tance(GetType(D ouble),
Data.GetUpperBo und(0) + 1)
Data.CopyTo(sor tedData, 0)
Array.Sort(sort edData)
Return sortedData(sort edData.GetUpper Bound(0))
End Function
End Class
Nov 21 '05 #1
2 1328
In Visual Studio 2005 you will be able to use generics to create a template
for a class or method where you can pass a type as an argument to the
class/method at runtime.

For now, you can emulate this future behavior to some extent by adding
overloaded methods to the class you have started.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"Dave" <dave@4_rem_ove _scotts.com> wrote in message
news:e8******** ********@TK2MSF TNGP15.phx.gbl. ..
I know in C++ you can create class templates so the data type can be
defined during the declaration of an instance of a class. I was trying to
do something like that for a VB.NET class cut am not really sure where to
start.

Here is an example for a simple DataArray class definition that sets up an
array used for numerical data and adds some additional functionality to
the array. The overloaded new methods work okay, although I'm not sure if
it's the right way to go about doing this, but for the other methods do I
have to write an overloaded method for each data type, or can I set these
up to identify the type of array that was created for this instance of the
class?

Public Class DataArray
Public Data As Array
Public Sub New(ByVal dt As Array)
Data = dt
End Sub

Public Sub New(ByVal Size As Integer, ByVal DataType As Type)
Data = Array.CreateIns tance(DataType, Size)
End Sub

Public Function Max() As Double
' find maximum value of the area
Dim sortedData As Array
sortedData = Array.CreateIns tance(GetType(D ouble),
Data.GetUpperBo und(0) + 1)
Data.CopyTo(sor tedData, 0)
Array.Sort(sort edData)
Return sortedData(sort edData.GetUpper Bound(0))
End Function
End Class

Nov 21 '05 #2
In Visual Studio 2005 you will be able to use generics to create a template
for a class or method where you can pass a type as an argument to the
class/method at runtime.

For now, you can emulate this future behavior to some extent by adding
overloaded methods to the class you have started.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"Dave" <dave@4_rem_ove _scotts.com> wrote in message
news:e8******** ********@TK2MSF TNGP15.phx.gbl. ..
I know in C++ you can create class templates so the data type can be
defined during the declaration of an instance of a class. I was trying to
do something like that for a VB.NET class cut am not really sure where to
start.

Here is an example for a simple DataArray class definition that sets up an
array used for numerical data and adds some additional functionality to
the array. The overloaded new methods work okay, although I'm not sure if
it's the right way to go about doing this, but for the other methods do I
have to write an overloaded method for each data type, or can I set these
up to identify the type of array that was created for this instance of the
class?

Public Class DataArray
Public Data As Array
Public Sub New(ByVal dt As Array)
Data = dt
End Sub

Public Sub New(ByVal Size As Integer, ByVal DataType As Type)
Data = Array.CreateIns tance(DataType, Size)
End Sub

Public Function Max() As Double
' find maximum value of the area
Dim sortedData As Array
sortedData = Array.CreateIns tance(GetType(D ouble),
Data.GetUpperBo und(0) + 1)
Data.CopyTo(sor tedData, 0)
Array.Sort(sort edData)
Return sortedData(sort edData.GetUpper Bound(0))
End Function
End Class

Nov 21 '05 #3

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

Similar topics

220
19260
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
13
2397
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes. Two sub-classes have the relationship to communicate back and forth through this pointer. The pointer is responsible inside Top class for allocating and deallocating two sub-classes. CMemory class is responsible to allocate and deallocate memory...
133
8628
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
8
2095
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is, I've been playing with Qt in KDE on a Slackware 10.0 system, and following their cookbook exercises, and everything's working, and I have no clue what the code is doing, i.e.. how do I connect my brain to the ascii in the files to the stuff on...
51
2589
by: Richard Hengeveld | last post by:
Hi all, I'm trying to understand how pointers for function parameters work. As I understand it, if you got a function like: void f(int *i) { *i = 0; }
23
2405
by: JoeC | last post by:
I am a self taught programmer and I have figured out most syntax but desigining my programs is a challenge. I realize that there are many ways to design a program but what are some good rules to follow for creating a program? I am writing a map game program. I created several objects: board object that is an array of integers each number 0-5 is a kind of terrain, a terrain object that is an array of terrain types and each number of...
27
3869
by: jm | last post by:
I am having trouble understanding the purposes of an interface, even though the concept of interfaces is around me all the time (user interface, for example). I'm just not understanding software interfaces. Like anything else, it appears Interfaces are by design something that requires documentation. I know this may be obvious, but if I have a class A and I say, well, class A implements IMyInterface. The fact that it implements...
19
1686
by: Mary Pegg | last post by:
There's got to be a better way: if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; but it's late and my brain is frazzled. Any ideas, oh PHP gurus? --
20
3110
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in like 65% of the time of the second routine. Yet both do the same thing. However, the second one seems better in terms of the way the code is written since it helps encapsulate the transformation in the inner loop better making it easier to read,...
0
9926
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
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11095
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
10716
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...
0
10399
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...
0
9552
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7108
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();...
0
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3223
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.