|
-
May 11th, 2001, 03:48 AM
#1
Thread Starter
New Member
Property and Object Confusion ????
Is it possible that a property of an object become another object???
-
May 11th, 2001, 08:38 AM
#2
Junior Member
Properties
In the case of Object Orientation, think of a property as a 'placeholder' for information about the object.
ie.
Suppose you were creating a simple banking system and you created a Customer Object. This Object could contain methods to get the Customers account number, customer age etc.
It could also, for the duration of its creation, contain information anbout the customer name, address, customer id etc.
Based on this, the Properties could be the name, address and customr account.
Once you assign data to a property, the Object becomes STATEFUL or is said to HAVE STATE.
In general, an Object retains STATE or information only for its life, ie until you set it to nothing.
Just to contradict what I said about Object Life and STATE...
An Object can also retain its STATE after destruction, this is called OBJECT PERSISTANCE. (Dont be too worried about this at this point)
You can also have a STATELESS Object, this is an object that does not have Properties or does not retain data.
An example of this could be an Object that only contains Functions and Methods, such as a BankBalance Object.
The way it would work, would be that you would pass the required information (like CustomerID or Account Number) into the function, and get the result back from the Object.
ie
Public Function GetBankBalance (byVal CustomerID as Long) as Currency
'.......Get the balance code here....
End Function
(Pass in the customer id .... get back the balance...
Hopes this helps.
Mail me if not.
To imitate is human... to copy without recognition is theft.
-
May 17th, 2001, 05:03 AM
#3
Member
Robinm,
I am interested with your examples on the answer.
I have read a lot about this kind of example typically if related to object but still could not understand why you would create object for customer and set its property to Customers account number and customer age, etc.
Aren't those properties can be set on the database ?
Regards
-
May 21st, 2001, 07:03 AM
#4
Hyperactive Member
Aren't those properties can be set on the database ?
Uhmm yes, but the point of using objects is that you isolate code, and that you can just use the object to get something.
I often use classes to represent a record in the database, give it search methods, etc.
Now, if I need to have a customer-id entered, and I want to display the name, I only have to do
Dim c As New CCustomer
c.Read(txtCustD.Text)
lblCustName.Caption = c.Name
Set c = Nothing
or something like that.
Of course, you can write the code to access the database, but this makes it just easier to use (especially on large projects).
And this was just an easy example...
If I understood the main question correct though, he'd like to know how yuo can let a property pass an object. That's easy, just something like this:
usercontrol (or class) has a private variable of the type CDummy
Just write your property handler like
Public Property Get Dummy() As CDummy
Set Dummy = m_Dummy
End Propery
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|