Re: New to Classes, please help.



Thank you for the explanation. That clears things up a bit ;)

Thanks,

David Lozzi


"Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23aVnP0SNFHA.4092@xxxxxxxxxxxxxxxxxxxxxxx
> As David is "new to classes," I thought I'd follow up your excellent
> advice with a bit of more detailed information about classes.
>
> A class is a data type, just as an integer or a string. A data type
> specifies both the type of data stored in an instance of that type, as
> well as the amount of memory necessary to allocate to store that type of
> data. An Integer, for example, is a 32-bit storage space that contains an
> integer value (remember that underneath it all it's just 1s and 0s). A
> string is a pointer to an array of characters. Note that an array is also
> a data type, as well as a pointer. A pointer is the address in memory of
> the object being pointed to. It is the size of a memory address.
>
> Structures were clreated before classes. A structure is an aggregate data
> type (like an array), which can contain multiple data types in a single
> storage space. A simple structure, for example, could contain an integer
> and a string. The size of the structure would be 32-bits plus the size of
> the pointer to the string. A structure can also have process. That is, you
> can make a function a member of a structure. So, you can see by now that a
> structure is a primitve class of sorts.
>
> With the advnet of OOP, classes were created. Classes are basically
> structures, but have additional properties, such as Inheritance,
> Encapsulation, Polymorphism and Abstraction. For example, a class can have
> private or public members (plus several others). Private class members
> cannnot be accessed outside the class. Inheritance gives you the ability
> to EXTEND a class with an inherited class. By using Inheritance, all the
> characteristics of the base class are automatically attributed to the
> inherited class, which can extend the base class with additional
> properties or functionality.
>
> As to Shared classes and members: A program has 2 basic memory areas: The
> stack and the heap. The heap is where all the code for the program is
> loaded when the program starts. In a sense, it is an in-memory copy of the
> program, and all of its process and data. It is a single "instance" if you
> will, of all the code. As the program runs, functions are called.
> Ordinarily, a copy ("instance") of the function is placed on top of the
> stack, where it remains until the function returns. However, a static
> method or piece of data is not instantiated. A copy is not placed on the
> stack every time the method is called. Instead, the single "copy" in the
> heap is used. that single copy is used by all aspects of the program. As
> there is only one (hence "singleton"), it is not thread-safe. In a sense,
> it is "shared" by all functions that call it.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> What You Seek Is What You Get.
>
>
> "Peter MacMillan" <peter@xxxxxxxxxxxxx> wrote in message
> news:A5WdnXGT8L2k3dffRVn-sA@xxxxxxxxxxxxx
>> David Lozzi wrote:
>>> Howdy,
>>>
>>> I'm new to classes. Below is my class User. (is this a reserved
>>> namespace or class?) It works great, kind of. If I specify the username
>>> and password, the correct firstname and lastname are returned. For
>>> example, username dlozzi, password fun. It returns David Lozzi as full
>>> name. If I login as someone else on another computer, say username
>>> dsmith and password fun2, the second computer displays the correct
>>> fullname. HOWEVER if I refresh the page on the first computer where I
>>> logged in under dlozzi, the information is now dsmith's info. I believe
>>> I am just missing one small piece, but I just cannot find it. Should I
>>> be using Session states along with classes?
>>>
>>> Thanks!
>>>
>>
>>
>> Your problem is coming from all of your methods and properties being
>> shared. I'm not sure how to explain this without going all-out on OO
>> methodology... "shared" means there is only one of that thing for the
>> class.
>>
>> You're right to have the login method (method is an OO word for
>> procedure/function).
>>
>> You want something like:
>>
>> Public Class User
>> Private m_username As String
>>
>> Public Sub New()
>> End Sub
>>
>> Public Property Username() As String
>> Get
>> Return m_username
>> End Get
>> Set(ByVal value As String)
>> m_username = value
>> End Set
>> End Property
>>
>> Public Shared Function Login(ByVal username As String) As User
>>
>> Dim result As User
>> result = new User()
>> result.Username = username
>> return result
>>
>> End Function
>> End Class
>>
>>
>> (I don't guarantee that the above will work because I just typed it out
>> in my newsreader. It should show you what needs to be done).
>>
>> Now from whereever you're loging them in, you call the Login function to
>> get a User object. You can then store that User into the Session (say,
>> put it in Session("UserObject") or something like that.
>>
>> --
>> Peter MacMillan
>> e-mail/msn: peter@xxxxxxxxxxxxx icq: 1-874-927
>>
>> GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$ N
>> o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
>> y(--)
>
>


.



Relevant Pages

  • Re: [1/1][PATCH] nproc v2: netlink access to /proc information
    ... Nproc, on the other hand, uses field IDs to identify information. ... Data type ID ... For strings, the string itself is prepended with a u32 indicating the ... the kernel suggests "VmShared" as a label, "%8u" for formatting, ...
    (Linux-Kernel)
  • Re: Insert values into Table
    ... See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials. ... string in code, and let me ask you a question as well. ... Is this column a date data type or a text string? ...
    (microsoft.public.access.modulesdaovba)
  • Re: Dates
    ... The conversion of a char data type to a datetime data type resulted in an ... out-of-range datetime value. ... System.Data.Common.DbDataAdapter.FillFromReader(Object data, String ... srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: runtime error with Mask edit control
    ... DateOfBirth property is a string. ... If no value is entered into the Property, the database stores a null. ... > its data type (one would assume the same as the property, ...
    (microsoft.public.vb.controls)
  • Re: Trigger to delete newly updated or inserted record??
    ... throwing extra records in the SQL tables. ... > create trigger t_iu_deletestooopidrecord on mytable for insert, ... > if a certain field is equal to a string. ... > David Lozzi ...
    (microsoft.public.sqlserver.programming)

Loading