473,847 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending intrinsic classes

Hello all,

i was just curious if anyone whos been playing with VS2005 could tell me...

In javascript (and java??) you can alter the prototypes for an object in
your project. I dont remember the syntax exactly, but basically you do
something like:

function String.prototyp e.mySplit(myArg s){...do something...}

and then any instance of a String object in that project has a new method
called "mySplit".
This isnt something by some chance that we will be able to do with intrinsic
objects in the framework in VS2005, is it?

I know it can be done by inheriting the intrinsic and extending it with a
new class in my project, but thats a lot heavier and more convoluted.

Cheers,
- Arthur Dent.
Nov 21 '05 #1
7 1646
"A Traveler" <hi************ *********@yahoo .com> wrote in message
news:Oj******** ******@TK2MSFTN GP15.phx.gbl...
Hello all,

i was just curious if anyone whos been playing with VS2005 could tell
me...

In javascript (and java??) you can alter the prototypes for an object in
your project. I dont remember the syntax exactly, but basically you do
something like:

function String.prototyp e.mySplit(myArg s){...do something...}

and then any instance of a String object in that project has a new method
called "mySplit".
This isnt something by some chance that we will be able to do with
intrinsic objects in the framework in VS2005, is it?

I know it can be done by inheriting the intrinsic and extending it with a
new class in my project, but thats a lot heavier and more convoluted.


Most people would disagree and say that the prototype mechanism used in
JavaScript (but not Java) is the convoluted method they used of avoiding the
"normal" OO technique of inheritance.

----
John Saunders

BTW, you are probably aware that there is no relationship between Java and
JavaScript (nee LiveScript) except for the name, which sounded "cool", so
they changed it.
Nov 21 '05 #2
| I know it can be done by inheriting the intrinsic and extending it with a
| new class in my project, but thats a lot heavier and more convoluted.

actually, the former is a lot heavier since *all* string objects will now
carry the prototype extentions rather that just the one's you declare as the
new extended type class that inherits from string. as far as convolution,
again the former looses out. ever try and track down which js file actually
contains the prototype definition when there are several js files
included/referenced in a web page? add to that, prototypes of your prototype
of the original string object (spread among multiple files)...or a prototype
of a prototype of a prototype of the original string object (spread among
multiple files)...ad nausium.

i don't know why you'd want to do this in vb.net and don't think that you
can. it would be a maintainence nightmare.
Nov 21 '05 #3
> ever try and track down which js file actually
contains the prototype definition when there are several js files
True, anything can be misused, and im not saying its something to go crazy
with.
But sometimes it could be useful. For example. Something i do Quite
frequently with
my strings is a port of Oralce's NVL function, but for strings so
essentially it pseudo-codes as:

If strVal = "" Then Return NullValue Else Return strVal

This is something i do very frequently in my code, and it would be nice
instead of having to make a
new class (or module), and writing this function, then having to imports the
module when i need it,
to just extend the String object for the project scope to have a new method
NVL(NullValue as String)

But, its not a big deal. I was just curious.

Thanks.

"steve" <a@b.com> wrote in message
news:10******** *****@corp.supe rnews.com...| I know it can be done by inheriting the intrinsic and extending it with a
| new class in my project, but thats a lot heavier and more convoluted.

actually, the former is a lot heavier since *all* string objects will now
carry the prototype extentions rather that just the one's you declare as
the
new extended type class that inherits from string. as far as convolution,
again the former looses out. ever try and track down which js file
actually
contains the prototype definition when there are several js files
included/referenced in a web page? add to that, prototypes of your
prototype
of the original string object (spread among multiple files)...or a
prototype
of a prototype of a prototype of the original string object (spread among
multiple files)...ad nausium.

i don't know why you'd want to do this in vb.net and don't think that you
can. it would be a maintainence nightmare.

Nov 21 '05 #4
| If strVal = "" Then Return NullValue Else Return strVal
|
| This is something i do very frequently in my code, and it would be nice
| instead of having to make a
| new class (or module), and writing this function, then having to imports
the
| module when i need it,
| to just extend the String object for the project scope to have a new
method
| NVL(NullValue as String)

this is a big deal when you have multiple developers on a project expecting
strings to behave like strings but now have to track down why they just set
strVal = "" and the next line calls to get strVal and it returns something
other than "". this is why there are well defined oop standards that most
languages follow...even php. all objects should build off of a base
definition where the new derivative must be referenced to get the new
functionality. "" is not nothing/null anyway...and, what happens when the
NullValue is itself "" (watch your processor go crazy on that one)! if you
could prototype your string object in this manner, then setting a string to
"" would cause your nvl function to validate and reset the variable to a nvl
of "" (were that the NullValue)...th is would start the validate/reset loop
again...and again...and again...those are the types of issues you get when
considering the alteration of an object by javascript methodology where the
actual base class is altered and not a derivative thereof.

hth,

steve
Nov 21 '05 #5
Arthur,
Prototypes as found in javascript (but not java) are not in VB.NET 2005, nor
C# 2005.
I know it can be done by inheriting the intrinsic and extending it with a
new class in my project, but thats a lot heavier and more convoluted. You do realize that all the "intrinsic" types are either NotInheritable
(String) or value types (which are inherently NotInheritable) so this is not
an other either.

Hope this helps
Jay

"A Traveler" <hi************ *********@yahoo .com> wrote in message
news:Oj******** ******@TK2MSFTN GP15.phx.gbl... Hello all,

i was just curious if anyone whos been playing with VS2005 could tell
me...

In javascript (and java??) you can alter the prototypes for an object in
your project. I dont remember the syntax exactly, but basically you do
something like:

function String.prototyp e.mySplit(myArg s){...do something...}

and then any instance of a String object in that project has a new method
called "mySplit".
This isnt something by some chance that we will be able to do with
intrinsic objects in the framework in VS2005, is it?

I know it can be done by inheriting the intrinsic and extending it with a
new class in my project, but thats a lot heavier and more convoluted.

Cheers,
- Arthur Dent.

Nov 21 '05 #6
Nah, you misunderstood my code. It wouldnt be to reset the value of the
object if it went 'null'. It would more likely be a method or property,
something like

Class String
...........
Public ReadOnly Property NVL(NullValue As String) As String
Get
If Me.Value = "" Then Return NullValue Else Return Me.Value
End Get
End Function
...........
End Class

But since its not possible, its not really an issue anyway.
Thanks. :)

"steve" <a@b.com> wrote in message
news:10******** *****@corp.supe rnews.com...
| If strVal = "" Then Return NullValue Else Return strVal
|
| This is something i do very frequently in my code, and it would be nice
| instead of having to make a
| new class (or module), and writing this function, then having to imports
the
| module when i need it,
| to just extend the String object for the project scope to have a new
method
| NVL(NullValue as String)

this is a big deal when you have multiple developers on a project
expecting
strings to behave like strings but now have to track down why they just
set
strVal = "" and the next line calls to get strVal and it returns something
other than "". this is why there are well defined oop standards that most
languages follow...even php. all objects should build off of a base
definition where the new derivative must be referenced to get the new
functionality. "" is not nothing/null anyway...and, what happens when the
NullValue is itself "" (watch your processor go crazy on that one)! if you
could prototype your string object in this manner, then setting a string
to
"" would cause your nvl function to validate and reset the variable to a
nvl
of "" (were that the NullValue)...th is would start the validate/reset loop
again...and again...and again...those are the types of issues you get when
considering the alteration of an object by javascript methodology where
the
actual base class is altered and not a derivative thereof.

hth,

steve

Nov 21 '05 #7
gotcha.

good luck.
Nov 21 '05 #8

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

Similar topics

5
2948
by: needin4mation | last post by:
Hi, I read this in a book about the Xml classes in c#: "These classes are abstract and therefore must be extended." I just wanted to know what this statement means. I know it is not in context, but the author gave it in such a matter that it appears experience folks will know what it means to say a class is abstract and extended. Thanks.
5
3183
by: Alan Ho | last post by:
What are intrinsic objects of asp.net? thx
1
2287
by: Sarge | last post by:
Hi all, tough question. Apologies for the cross posting but it is an interesting architectural problem and I think deserves a wide audience. What is the best way to extend web service proxy classes so we can add our own methods and properties? We have an application that passes a deep hierarchical structure (four nodes deep) between a webservice and a smart client. We have built the web service using the Contract First Web Service...
9
2189
by: Robert | last post by:
Hi, I thought it would be a good idea to make specialised error objects. So I did something like this: function IndexOutOfBoundsException(message) { Error.call(this, message); }
9
5795
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Data_List(); } }
13
2128
by: interec | last post by:
I have some code in Java that I need to translate into C++. My Java code defines a class hierarchy as follows: // interface IA public interface IA { public abstract void doA(); } // interface IB
7
3393
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced python developers. II want to add some more KEYWORDS and DATATYPES into the python script apart from the existing ones. It would be really great if anybody could guide me as which files and
5
2128
by: Wolfgang Hanke | last post by:
Hello, I want to extend multiple Controls like TextBox, Label, ComboBox etc. with the same new featureset (for Example all need a Method getSomething()) Because I cant alter their Base-Class I have to write one new class for each Control like MyTextBox, MyLabel, MyComboBox implementing IMyControlInterface. The Code for each Control is exactly the same but C# offers no way to "include" some code.
8
2383
by: Floortje | last post by:
Hi i have been struggeling with this question for quite some time now. I have some helper classes that handle images (upload an image, create thumbnails and show a imagelist), links (add link, edit link, show linklist), comments (add comment, show commentlist) etc. I do not need all this functionality on every page. Ideally I could just extend the controller like this
1
10706
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
10338
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
9482
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...
1
7882
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
7056
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
5719
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4528
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 we have to send another system
3
3164
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.