473,657 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Me vs. MyClass

What is the difference between the Me and the MyClass keywords? I
understand Me that it represents the specific instance of the class.
When you're inside the object instance, it refers to itself using the
Me keyword. What is the MyClass keyword used for?

Nov 21 '05 #1
24 3567
MyClass is used in situations where the current class (me) overrides a
member from the base class (MyBase). Now, let's assume the in the base
class version of the overridden member, you want to ensure that a BASE class
member gets used by the child class, you would use the MyClass keyword in
the BASE class's overrideable member.

In the end, when the child class calls its own version of an overridable
member, the value from the BASE class that was marked as MyClass still gets
used.
"Water Cooler v2" <wt*****@yahoo. com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
What is the difference between the Me and the MyClass keywords? I
understand Me that it represents the specific instance of the class.
When you're inside the object instance, it refers to itself using the
Me keyword. What is the MyClass keyword used for?

Nov 21 '05 #2
On 2005-09-03, Water Cooler v2 <wt*****@yahoo. com> wrote:
What is the difference between the Me and the MyClass keywords? I
understand Me that it represents the specific instance of the class.
When you're inside the object instance, it refers to itself using the
Me keyword. What is the MyClass keyword used for?


MyClass ignores any derived class overrides. This is one of those
instances where the help file is actually very helpful. Either type MyClass into
help, or check out...

http://msdn.microsoft.com/library/de...keymyclass.asp

(sorry about any breaks in the url)

Nov 21 '05 #3
On 2005-09-03, Scott M. <s-***@nospam.nosp am> wrote:
MyClass is used in situations where the current class (me) overrides a
member from the base class (MyBase). Now, let's assume the in the base
class version of the overridden member, you want to ensure that a BASE class
member gets used by the child class, you would use the MyClass keyword in
the BASE class's overrideable member.

In the end, when the child class calls its own version of an overridable
member, the value from the BASE class that was marked as MyClass still gets
used.


I thought I understood this stuff, but I don't follow that at all. How
do you "mark a value as MyClass"? I thought MyClass was something you
used when invoking a member, not when declaring it.

And AFAIK, a child class is always going to get it's own overridden
members unless it specifically calls into the base class. The base class
can ignore the overrides in its own function calls, but can't make any
changes to the function calls that the child class makes.

Am I missing something, or just confused by the wording here?
Nov 21 '05 #4
dfoster,

I think your understanding is right. Scott M. probably did not word it
correctly.

And now, that link you have mentioned from the MSDN brings us to a very
important question.

What if I changed the interface/pointer type of the object from whom I
invoke the MyMethod sub to that of the base class.

So, instead of:

Dim TestObj As DerivedClass = New DerivedClass
TestObj.UseMe() ' Displays "Derived class string".
TestObj.UseMyCl ass() ' Displays "Base class string".
TestObj.MyMetho d()
that the documentation has, what if I do this:

Dim Base As BaseClass = New DerivedClass
Base.MyMethod()
Base.UseMe()
Base.UseMyClass ()

It nullifies the v-table entries and shadows the derived class
overrides just as in the previous example. This proves that one must
not expect polymorphic behaviour from your class if you invoke a method
with the MyClass keyword.
Thanks for all your replies.

Regards,
Sathyaish
PS: I am Water Cooler v2. My posting quota on this machine is over, so
I have switched accounts.

Nov 21 '05 #5
On 2005-09-04, Sathyaish <sa*******@gmai l.com> wrote:
dfoster,

I think your understanding is right. Scott M. probably did not word it
correctly.

And now, that link you have mentioned from the MSDN brings us to a very
important question.

What if I changed the interface/pointer type of the object from whom I
invoke the MyMethod sub to that of the base class.
It wouldn't matter.

So, instead of:

Dim TestObj As DerivedClass = New DerivedClass
TestObj.UseMe() ' Displays "Derived class string".
TestObj.UseMyCl ass() ' Displays "Base class string".
TestObj.MyMetho d()
That last displays "Derived Class string"

that the documentation has, what if I do this:

Dim Base As BaseClass = New DerivedClass
Base.MyMethod()
Still displays "Derived class string"
Base.UseMe()
Base.UseMyClass ()

It nullifies the v-table entries and shadows the derived class
overrides just as in the previous example. This proves that one must
not expect polymorphic behaviour from your class if you invoke a method
with the MyClass keyword.


I'd word that differently. From the callers POV, you still get
polymorphism. MyMethod will display differently depending on whether the
caller created a BaseClass or a DerivedClass, regardless of whether the
variable is declared as a BaseClass or a DerivedClass. A DerivedClass
instance acts the same way even if you call methods through a variable
declared as BaseClass.
The variable declaration simply doesn't matter, only the definition does,
and that's the essence of polymorphism.

I struggle to think of a use for MyClass that doesn't represent horrible
design. Does anyone know if this is actually used in the framework
anywhere?
Nov 21 '05 #6
>you still get polymorphism.

Surely, you get polymorphism. I meant that *for the method call
qualified by MyClass, the polymorphic behaviour is overlooked/shadowed.*

Nov 21 '05 #7
On 2005-09-04, Sathyaish <sa*******@gmai l.com> wrote:
you still get polymorphism.


Surely, you get polymorphism. I meant that *for the method call
qualified by MyClass, the polymorphic behaviour is overlooked/shadowed.*


We might just be saying the same thing, but your example was changing...

Dim TestObj As DerivedClass = New DerivedClass

to

Dim Base As BaseClass = New DerivedClass

That's entirely polymorphic. The caller has no clue that MyClass was
being used anywhere, nor should it. Those two examples result in the
exact same code paths.

I'm not really sure what that example is supposed to show. Changing the
declaration of the instance variable doesn't affect anything.
Nov 21 '05 #8
dfoster,
| I struggle to think of a use for MyClass that doesn't represent horrible
| design. Does anyone know if this is actually used in the framework
| anywhere?
Chaining constructors, such as:

Public Class SomeCollection

Public Const DefaultValue As String = ""
Public Const DefaultCapacity As Integer = 16

Public Sub New()
MyClass.New(Def aultValue, DefaultCapacity )
End Sub

Public Sub New(ByVal capacity As Integer)
MyClass.New(Def aultValue, capacity)
End Sub

Public Sub New(ByVal value As String)
MyClass.New(val ue, DefaultCapacity )
End Sub

Public Sub New(ByVal value As String, ByVal capacity As Integer)

End Sub

...

End Class

Granted you could use Optional parameters instead at the expense of being
friendly to C#...

For methods other then constructors, I cannot think of a good example where
I would, much less have, used it. However I expect if it was not available,
then we would all have good examples of needing it ;-)

Hope this helps
Jay

"dfoster" <df*****@woofix .local.dom> wrote in message
news:sl******** ************@lo calhost.localdo main...
| On 2005-09-04, Sathyaish <sa*******@gmai l.com> wrote:
| > dfoster,
| >
| > I think your understanding is right. Scott M. probably did not word it
| > correctly.
| >
| > And now, that link you have mentioned from the MSDN brings us to a very
| > important question.
| >
| > What if I changed the interface/pointer type of the object from whom I
| > invoke the MyMethod sub to that of the base class.
|
| It wouldn't matter.
|
| >
| > So, instead of:
| >
| > Dim TestObj As DerivedClass = New DerivedClass
| > TestObj.UseMe() ' Displays "Derived class string".
| > TestObj.UseMyCl ass() ' Displays "Base class string".
| > TestObj.MyMetho d()
|
| That last displays "Derived Class string"
|
| >
| > that the documentation has, what if I do this:
| >
| > Dim Base As BaseClass = New DerivedClass
| > Base.MyMethod()
|
| Still displays "Derived class string"
|
| > Base.UseMe()
| > Base.UseMyClass ()
| >
| > It nullifies the v-table entries and shadows the derived class
| > overrides just as in the previous example. This proves that one must
| > not expect polymorphic behaviour from your class if you invoke a method
| > with the MyClass keyword.
|
| I'd word that differently. From the callers POV, you still get
| polymorphism. MyMethod will display differently depending on whether the
| caller created a BaseClass or a DerivedClass, regardless of whether the
| variable is declared as a BaseClass or a DerivedClass. A DerivedClass
| instance acts the same way even if you call methods through a variable
| declared as BaseClass.
|
|
| The variable declaration simply doesn't matter, only the definition does,
| and that's the essence of polymorphism.
|
| I struggle to think of a use for MyClass that doesn't represent horrible
| design. Does anyone know if this is actually used in the framework
| anywhere?
|
|
Nov 21 '05 #9
No, your understanding is wrong and my wording is right.

You don't declare something as MyClass (nor, did I say that you do), you
reference something that way. An example is best...

'************** *************** *************** **
Public Class A
Public Overridable Function DoFoo() As String
'Do something here
End Function

Public Overridable Sub Foo()
MyClass.DoFoo()
End Sub
End Class
'************** *************** *************** **
Public Class B
Inherits A

Public Overrides Function DoFoo() As String
'Do something here
End Function

Public Sub SomethingElse
Foo()
End Sub
End Class
'************** *************** *************** **

If I were to now make an instance of class "B" and call its "SomethingE lse"
method the SomethingElse method from the "B" class then calls the "Foo"
method of the base class.

In the base class (A), the "Foo" method calls an overridable method called
"DoFoo". There is a "DoFoo" method in BOTH classes. Without the "MyClass"
keyword in the base class, the child class would wind up using the
overridden "DoFoo" method in the child class, but because of the "MyClass"
keyword, calling "SomethingE lse" in the child class calls "Foo" in the base
class and "Foo" in the base class uses "DoSomethin g" from the SAME CLASS as
"DoSomethin g" is running (which is the base class).

It is a bit confusing, but if you trace my explanation, you will see that
without the "MyClass" keyword, the base class method "Foo" would use the
child class method "DoFoo" instead of its own.

-Scott


"Sathyaish" <sa*******@gmai l.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
dfoster,

I think your understanding is right. Scott M. probably did not word it
correctly.

And now, that link you have mentioned from the MSDN brings us to a very
important question.

What if I changed the interface/pointer type of the object from whom I
invoke the MyMethod sub to that of the base class.

So, instead of:

Dim TestObj As DerivedClass = New DerivedClass
TestObj.UseMe() ' Displays "Derived class string".
TestObj.UseMyCl ass() ' Displays "Base class string".
TestObj.MyMetho d()
that the documentation has, what if I do this:

Dim Base As BaseClass = New DerivedClass
Base.MyMethod()
Base.UseMe()
Base.UseMyClass ()

It nullifies the v-table entries and shadows the derived class
overrides just as in the previous example. This proves that one must
not expect polymorphic behaviour from your class if you invoke a method
with the MyClass keyword.
Thanks for all your replies.

Regards,
Sathyaish
PS: I am Water Cooler v2. My posting quota on this machine is over, so
I have switched accounts.

Nov 21 '05 #10

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

Similar topics

32
2719
by: Mario Fratelli | last post by:
MyClass *p = new MyClass; MyClass *p = new MyClass(); do they mean something different? Thanks a lot, Mario Fratelli.
11
2524
by: modemer | last post by:
If I define the following codes: void f(const MyClass & in) {cout << "f(const)\n";} void f(MyClass in) {cout<<"f()\n";} MyClass myclass; f(myclass); Compiler complain that it can't find the best match. Anyone could give a detail explanation in theory? Which one is good?
4
2399
by: John | last post by:
I have a function declaration that gives an error while compiling. Can anyone help me figure this one out? inline void create(const std::vector< myclass >& plist, std::vector< myclass >::iterator left, std::vector< myclass >::iterator right); x.hpp:153: error: `class std::vector<myclass, D>, std::alloca
5
1500
by: Gunnar G | last post by:
What is the difference between the two lines in the main function? class MyClass{ ....}; int main(){ MyClass a(); MyClass a; }
3
1522
by: janzon | last post by:
Hi! When defining a new object m of class MyClass, with no parameters to the constructor, one is supposed to write "MyClass m;". If one wants to pass a parameter p to the constructor, one is supposed to write "MyClass m(p);". It doesn't work if one writes "MyClass m();" when one wants to pass zero parameters. Why is that? It seems inelegant and non-symmetric to me. What reason is there behind this? / Me, seeking insights into C++
9
6985
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus, (MyClass is object) should always evaluate as true. However, if I have a method with the following signature:
4
11423
by: shapper | last post by:
Hello, I am getting various records from a database: Dim ds As DataSet = db.ExecuteDataSet(dbc) Each record has 3 fields: Id, Name and Text. I have a class named MyClass with 3 properties Id, Name and Text.
9
2361
by: devloop | last post by:
Hi, I am a JAVA developer who just started with php5 (on a WAMPP with php5.2.1). I´ve the following problem with a little class (I wanted to put objects into the array later but even with simple strings it doesn´t work!!!!!!!!!). The output doesn´t show any letters/strings when I call the method toHtml().
0
1300
by: Curious | last post by:
Hi, I've created a windows form application. I have a form and a .cs file in the application, and I've renamed them to MyDialog and MyClass.cs. In MyClass.cs, I have a member called "Publisher" and I assign value to this member in MyClass.cs. In MyDialog (upon a button click), I'll need to use the current value of "Publisher" from MyClass.cs. But I don't know how. Anyone can
0
8395
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
8310
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,...
1
8503
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
8605
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
7330
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
5632
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
4155
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...
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.