|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Method.property stringIn the framework of most OOP is the underlying ability to string commands
like Thread.CurrentThread.GetHashCode(). I have tried to find how this is done, unsuccessfully I might add. I feel that it possibly one of those building-block concepts that I’ve missed as I studied VB and .net specifically. Some times I feel like returning to VB6; I was safe there! When answering please be gentle and speak slowly. I’m old and out of sorts with the acronym world most of you live in. Thanks in advance. Steve -- You don't know, what it is that you don't know! "StumpedSteve" <StumpedSt***@discussions.microsoft.com> a écrit dans le message de news: F66266FF-43F4-4D24-9DE1-6CD2E3285***@microsoft.com...| In the framework of most OOP is the underlying ability to string commands Thread.CurrentThread.GetHashCode() is not stringing commands, it is calling | like Thread.CurrentThread.GetHashCode(). I have tried to find how this is | done, unsuccessfully I might add. I feel that it possibly one of those | building-block concepts that I've missed as I studied VB and .net | specifically. Some times I feel like returning to VB6; I was safe there! a method on a property. Thread is the name of a class, CurrentThread is the name of a static property of that class and GetHashCode() is an instance method (derived from System.Object) on the Thread object returned by the CurrentThread property. A quick example would be : public class Thread { public static Thread CurrentThread { get { return // current thread from list of threads } } public override int GetHashCode() { return // code that calculates hash code } } Does that help or confuse further ? :-) Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Thank you so much for your reply. I should have written long ago, could have
saved me many hours of trial. Could you recommend a book that would define this concept? I have six books from some highly recommended sources Sams, Microsoft Press, Wrox and I still cannot find this in any of them. Maybe I need to step to the next level. When I attempt to make a property static it is disallowed in VB.net. It looks like you are using a higher level language like C++, I am not familiar with the {} delineation. At least you have given me the name of the process that I can research. Thanks Again. Steve -- Show quoteYou don’t know everything you don’t know! Don’t you wish you’d paid better attention in school? "Joanna Carter [TeamB]" wrote: > "StumpedSteve" <StumpedSt***@discussions.microsoft.com> a écrit dans le > message de news: F66266FF-43F4-4D24-9DE1-6CD2E3285***@microsoft.com... > > | In the framework of most OOP is the underlying ability to string commands > | like Thread.CurrentThread.GetHashCode(). I have tried to find how this is > | done, unsuccessfully I might add. I feel that it possibly one of those > | building-block concepts that I've missed as I studied VB and .net > | specifically. Some times I feel like returning to VB6; I was safe there! > > Thread.CurrentThread.GetHashCode() is not stringing commands, it is calling > a method on a property. > > Thread is the name of a class, CurrentThread is the name of a static > property of that class and GetHashCode() is an instance method (derived from > System.Object) on the Thread object returned by the CurrentThread property. > > A quick example would be : > > public class Thread > { > public static Thread CurrentThread > { > get { return // current thread from list of threads } > } > > public override int GetHashCode() > { > return // code that calculates hash code > } > } > > Does that help or confuse further ? :-) > > Joanna > > -- > Joanna Carter [TeamB] > Consultant Software Engineer > > > "StumpedSteve" <StumpedSt***@discussions.microsoft.com> a écrit dans le message de news: 55B23DD4-6227-4D07-A853-9ADD75B67***@microsoft.com...| Thank you so much for your reply. I should have written long ago, could I'm sorry but I don't know of any books on this subject, but you should use have | saved me many hours of trial. Could you recommend a book that would define | this concept? I have six books from some highly recommended sources Sams, | Microsoft Press, Wrox and I still cannot find this in any of them. Maybe I | need to step to the next level. Google or similar to look up phrases like "VB.NET properties" or whatever you need. There is a mass of information out there on the web for free. | When I attempt to make a property static it is disallowed in VB.net. It I am using C#, but most things that are available in C# are also available | looks like you are using a higher level language like C++, I am not familiar | with the {} delineation. At least you have given me the name of the process | that I can research. in VB.NET, it's just that a lot of examples semm to be in either one or the other language. I have only ever used VB3 for a week a long time ago just before I switched to Delphi 1, so I don't like and am not very good at VB syntax. Static properties are allowed in VB.NET, but you have to use the "shared" keyword; here is a sample declaration : Private Shared x As Integer Public Shared Property X() As Integer Get Return x End Get Set x = value End Set End Property Do you understand what a static (shared) property is and what the difference is between it and an instance property ? Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Instance variable I am familiar with although instance properties I am not.
Although I know the genre used for defining one entity usually crosses over to another. So I would guess that instance properties have a limited scope within the class they reside, although, again, I don’t find any reference to it in my books. So I would have to ask; would I set the scope of a resident property to “friend†so it could be accessed across class borders? While in my limited exposure to VB.net I have not used shared properties I understand them to be accessible without instantiating the class they reside. They share their allegiance to the class as well as the instantiated object. I also understand that the have a whole new “kettle†of rules that must be followed. I also know that there is a lot I don’t know about them, and what I think I know may be misinterpreted. All this being said; the answer is NO. Please teach me. Thank you for your patience for this old dog. -- Show quoteYou don’t know everything you don’t know! Don’t you wish you’d paid better attention in school? "Joanna Carter [TeamB]" wrote: > "StumpedSteve" <StumpedSt***@discussions.microsoft.com> a écrit dans le > message de news: 55B23DD4-6227-4D07-A853-9ADD75B67***@microsoft.com... > > | Thank you so much for your reply. I should have written long ago, could > have > | saved me many hours of trial. Could you recommend a book that would > define > | this concept? I have six books from some highly recommended sources Sams, > | Microsoft Press, Wrox and I still cannot find this in any of them. Maybe > I > | need to step to the next level. > > I'm sorry but I don't know of any books on this subject, but you should use > Google or similar to look up phrases like "VB.NET properties" or whatever > you need. There is a mass of information out there on the web for free. > > | When I attempt to make a property static it is disallowed in VB.net. It > | looks like you are using a higher level language like C++, I am not > familiar > | with the {} delineation. At least you have given me the name of the > process > | that I can research. > > I am using C#, but most things that are available in C# are also available > in VB.NET, it's just that a lot of examples semm to be in either one or the > other language. I have only ever used VB3 for a week a long time ago just > before I switched to Delphi 1, so I don't like and am not very good at VB > syntax. > > Static properties are allowed in VB.NET, but you have to use the "shared" > keyword; here is a sample declaration : > > Private Shared x As Integer > > Public Shared Property X() As Integer > Get > Return x > End Get > Set > x = value > End Set > End Property > > Do you understand what a static (shared) property is and what the difference > is between it and an instance property ? > > Joanna > > -- > Joanna Carter [TeamB] > Consultant Software Engineer > > > "StumpedSteve" <StumpedSt***@discussions.microsoft.com> a écrit dans le message de news: BF004E9C-8826-4623-964B-72967BF83***@microsoft.com...Show quote | Instance variable I am familiar with although instance properties I am Let me start by just going over some basics :not. | Although I know the genre used for defining one entity usually crosses over | to another. So I would guess that instance properties have a limited scope | within the class they reside, although, again, I don't find any reference to | it in my books. So I would have to ask; would I set the scope of a resident | property to "friend" so it could be accessed across class borders? | | While in my limited exposure to VB.net I have not used shared properties I | understand them to be accessible without instantiating the class they reside. | They share their allegiance to the class as well as the instantiated object. | I also understand that the have a whole new "kettle" of rules that must be | followed. I also know that there is a lot I don't know about them, and what | I think I know may be misinterpreted. A class is like a cookie cutter, an object or instance is like the cookies that the cutter creates. Classes can contain fields, methods properties and events. These are known as members and can be either static or instance members. Static members belong to the "cookie cutter" (class) and, as you rightly say, can be accessed without having to create an instance of the class. Fields hold state and should usually only be of private visibility. This then means that we need a mechanism that allows us to expose the values in these fields. One mechanism is to add public accessor methods : public class Person { private string name; public string GetName() { return name; } public void SetName(string value) { name = value; // fire notification event or something } } This then requires us to call these methods in code like this : { Person p = new Person(); p.SetName("Joanna"); Console.WriteLine(p.GetName()); } Properties allow us to talk to fields without making those fields public, but still allowing us to use a "field" syntax. public class Person { private string name; public string Name { get { return name; } set { name = value; // fire notification event or something } } } This then allows us to call these properties in code like this : { Person p = new Person(); p.Name = "Joanna"; Console.WriteLine(p.Name); } So you can think of properties as a sort of virtual field that also allows us to execute additional or consequential code when reading/writing a value from/to an object. You can also use a property to restrict a "field" to being read-only, or even write-only ! public class Person { private DateTime dateOfBirth; public TimeSpan Age { get { return DateTime.Now = dateOfBirth; // pseudocode } } public DateTime DateOfBirth { set { dateOfBirth = value; } } } Properties can also be virtual or even abstract, which means that we can add or change what happens when a value is read/written in derived classes : public class Base { private string value; public virtual string Value { get { return value; } set { this.value = value; } } } public class Derived : Base { public override string Value { get { return base.Value; } set { base.Value = value; // do something more } } } Does that help ? If you need further help, then just ask. Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Joanna
Thanks for being patient with me. I still cannot find my “missing link†to put this together. Maybe it’s true, “You can’t teach an old dog new tricks!†I’d like to take just a few more moments of your time. Maybe I am attempting something that is incorrect, or my methodology is skewed. I would like to throw out my thought path and have you take a look. I have several areas of my program where I have to retrieve data from a database. I retain the data in table objects where each area can manipulate it to suit depending on user interface. I have several working methods to retrieve this data, assemble SQL statements, retrieve the data column number (given a name), and data (given a row). I would however, like to streamline this into an OOP “like†presentation. I have drawn a map of the outcome that I would like to share; I’ll try to be brief. GetData(SQL, Area) method to retrieve the data and store it in the “areas†data table object. GetData(Area).Col(ColumnName) Overloaded GetData and property Col returns the column number from the given table object {Area} of the given column name. GetData(Area).Col(col Number).Row(RowNumber) Overload Col to set or get the property value Row of the given area object, at the given Col. Seems do-able doesn’t it? I think that by your instruction I would make a shared (static) Col property within the GetData Class that would return the Column position from the given column name. Then would I instantiate the Col class from within the GetData Class to call the overloaded Shared Method "Col" and place the Shared (static) Row property in the Col Class? Or could I inherit the GetData class? I have tried all but haven’t succeeded in any. If I knew the correct path I would find the proper syntax. (I doubt that I can overload a method and a property of the same name so I’ll need to massage that some.) Steve -- Show quoteYou don’t know everything you don’t know! Don’t you wish you’d paid better attention in school? "Joanna Carter [TeamB]" wrote: > "StumpedSteve" <StumpedSt***@discussions.microsoft.com> a écrit dans le > message de news: BF004E9C-8826-4623-964B-72967BF83***@microsoft.com... > > | Instance variable I am familiar with although instance properties I am > not. > | Although I know the genre used for defining one entity usually crosses > over > | to another. So I would guess that instance properties have a limited > scope > | within the class they reside, although, again, I don't find any reference > to > | it in my books. So I would have to ask; would I set the scope of a > resident > | property to "friend" so it could be accessed across class borders? > | > | While in my limited exposure to VB.net I have not used shared properties I > | understand them to be accessible without instantiating the class they > reside. > | They share their allegiance to the class as well as the instantiated > object. > | I also understand that the have a whole new "kettle" of rules that must be > | followed. I also know that there is a lot I don't know about them, and > what > | I think I know may be misinterpreted. > > Let me start by just going over some basics : > > A class is like a cookie cutter, an object or instance is like the cookies > that the cutter creates. > > Classes can contain fields, methods properties and events. These are known > as members and can be either static or instance members. > > Static members belong to the "cookie cutter" (class) and, as you rightly > say, can be accessed without having to create an instance of the class. > > Fields hold state and should usually only be of private visibility. This > then means that we need a mechanism that allows us to expose the values in > these fields. One mechanism is to add public accessor methods : > > public class Person > { > private string name; > > public string GetName() > { > return name; > } > > public void SetName(string value) > { > name = value; > // fire notification event or something > } > } > > This then requires us to call these methods in code like this : > > { > Person p = new Person(); > > p.SetName("Joanna"); > > Console.WriteLine(p.GetName()); > } > > Properties allow us to talk to fields without making those fields public, > but still allowing us to use a "field" syntax. > > public class Person > { > private string name; > > public string Name > { > get { return name; } > set > { > name = value; > // fire notification event or something > } > } > } > > This then allows us to call these properties in code like this : > > { > Person p = new Person(); > > p.Name = "Joanna"; > > Console.WriteLine(p.Name); > } > > So you can think of properties as a sort of virtual field that also allows > us to execute additional or consequential code when reading/writing a value > from/to an object. > > You can also use a property to restrict a "field" to being read-only, or > even write-only ! > > public class Person > { > private DateTime dateOfBirth; > > public TimeSpan Age > { > get > { > return DateTime.Now = dateOfBirth; // pseudocode > } > } > > public DateTime DateOfBirth > { > set { dateOfBirth = value; } > } > } > > Properties can also be virtual or even abstract, which means that we can add > or change what happens when a value is read/written in derived classes : > > public class Base > { > private string value; > > public virtual string Value > { > get { return value; } > set { this.value = value; } > } > } > > public class Derived : Base > { > public override string Value > { > get { return base.Value; } > set > { > base.Value = value; > // do something more > } > } > } > > Does that help ? If you need further help, then just ask. > > Joanna > > -- > Joanna Carter [TeamB] > Consultant Software Engineer > > > > |
|||||||||||||||||||||||