473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Class Basics (Slightly OT?)

Hi All,

Being a classic ASP programmer, I'm trying to get to grips with OOP,
specifically using classes.

I have setup my class with various properties, so far so good. What I dont
quite get is the logic of using the properties.

E.g. If I want to get the RoadName property of my address class into a
database, do I do something like this...

Public function saveToDB()
strSQL = "Insert into TblName RoadName Values " & address.RoadName
bla bla bla....run the sql here!
End Function

Also, if I want to get a specific address from my DB and create an address
object from it, do I do something like this?

Public Function GetAddress(byval RoadName as String)
strsql = "select roadname fromtblname where roadname = " &
roadname
bla bla...run the SQL
address.roadname = dr("roadname")
End Function

I guess I just need someone to confirm my thinking is right on this, or if
not, point me in the right direction! :)

Thanks,
Simon.

--
I am using the free version of SPAMfighter for private users.
It has removed 2173 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!
Nov 19 '05 #1
5 977
You've got it.

Properties are nothing more than variables that are specific to an object.
"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:uc**************@TK2MSFTNGP15.phx.gbl...
Hi All,

Being a classic ASP programmer, I'm trying to get to grips with OOP,
specifically using classes.

I have setup my class with various properties, so far so good. What I dont
quite get is the logic of using the properties.

E.g. If I want to get the RoadName property of my address class into a
database, do I do something like this...

Public function saveToDB()
strSQL = "Insert into TblName RoadName Values " & address.RoadName
bla bla bla....run the sql here!
End Function

Also, if I want to get a specific address from my DB and create an address
object from it, do I do something like this?

Public Function GetAddress(byval RoadName as String)
strsql = "select roadname fromtblname where roadname = " &
roadname
bla bla...run the SQL
address.roadname = dr("roadname")
End Function

I guess I just need someone to confirm my thinking is right on this, or if
not, point me in the right direction! :)

Thanks,
Simon.

--
I am using the free version of SPAMfighter for private users.
It has removed 2173 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!

Nov 19 '05 #2
Cool - Thanks! :)

"Scott M." <s-***@nospam.nospam> wrote in message
news:eP**************@TK2MSFTNGP14.phx.gbl...
You've got it.

Properties are nothing more than variables that are specific to an object.
"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:uc**************@TK2MSFTNGP15.phx.gbl...
Hi All,

Being a classic ASP programmer, I'm trying to get to grips with OOP,
specifically using classes.

I have setup my class with various properties, so far so good. What I
dont
quite get is the logic of using the properties.

E.g. If I want to get the RoadName property of my address class into a
database, do I do something like this...

Public function saveToDB()
strSQL = "Insert into TblName RoadName Values " & address.RoadName
bla bla bla....run the sql here!
End Function

Also, if I want to get a specific address from my DB and create an
address
object from it, do I do something like this?

Public Function GetAddress(byval RoadName as String)
strsql = "select roadname fromtblname where roadname = " &
roadname
bla bla...run the SQL
address.roadname = dr("roadname")
End Function

I guess I just need someone to confirm my thinking is right on this, or
if
not, point me in the right direction! :)

Thanks,
Simon.

--
I am using the free version of SPAMfighter for private users.
It has removed 2173 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!


Nov 19 '05 #3
> Properties are nothing more than variables that are specific to an object.

Well, not exactly. FIELDS are variables that are global to a class. A
Property is actually a special entity that is composed of one or 2 methods
(functions), one for getting, and/or one for setting the Property. In other
words, a field is state, while a Property is process. A field is a container
for data. A Property is an amalgam of one or more processes that either
return or process data. Typically, a Property is used to expose and
encapsulate a Field. However, a Property doesn't have to be linked to any
data at all.

To give you an idea of what I'm describing, consider the 2 following
examples:

// Property that exposes a field
public class foo
{
private int _bar = 0; //field
public int bar // property
{
get
{
return _bar;
}
set
{
_bar = value;
}

}
}

public class foo
{
public int bar //property
{
get
{
return 0;
}
}
}

The simplified example above doesn't do justice to the possibilities of
properties. For example, let's say you create a class that draws a
rectangle. You could create a read-only property of that class that returns
the area of the rectangle, by multiplying the length times the width.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"Scott M." <s-***@nospam.nospam> wrote in message
news:eP**************@TK2MSFTNGP14.phx.gbl...
You've got it.

Properties are nothing more than variables that are specific to an object.
"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:uc**************@TK2MSFTNGP15.phx.gbl...
Hi All,

Being a classic ASP programmer, I'm trying to get to grips with OOP,
specifically using classes.

I have setup my class with various properties, so far so good. What I
dont
quite get is the logic of using the properties.

E.g. If I want to get the RoadName property of my address class into a
database, do I do something like this...

Public function saveToDB()
strSQL = "Insert into TblName RoadName Values " & address.RoadName
bla bla bla....run the sql here!
End Function

Also, if I want to get a specific address from my DB and create an
address
object from it, do I do something like this?

Public Function GetAddress(byval RoadName as String)
strsql = "select roadname fromtblname where roadname = " &
roadname
bla bla...run the SQL
address.roadname = dr("roadname")
End Function

I guess I just need someone to confirm my thinking is right on this, or
if
not, point me in the right direction! :)

Thanks,
Simon.

--
I am using the free version of SPAMfighter for private users.
It has removed 2173 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!


Nov 19 '05 #4
You're right Kevin. I thought that to go into that detail would be
splitting hairs. I thought (and still do) that the general analogy of
property to variable is a good beginning way to think about properties since
the purpose of a property is to maintain some sort of state of the object
and the purpose of a variable is to maintain some user defined state
information.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Or**************@TK2MSFTNGP14.phx.gbl...
Properties are nothing more than variables that are specific to an
object.


Well, not exactly. FIELDS are variables that are global to a class. A
Property is actually a special entity that is composed of one or 2 methods
(functions), one for getting, and/or one for setting the Property. In
other words, a field is state, while a Property is process. A field is a
container for data. A Property is an amalgam of one or more processes that
either return or process data. Typically, a Property is used to expose and
encapsulate a Field. However, a Property doesn't have to be linked to any
data at all.

To give you an idea of what I'm describing, consider the 2 following
examples:

// Property that exposes a field
public class foo
{
private int _bar = 0; //field
public int bar // property
{
get
{
return _bar;
}
set
{
_bar = value;
}

}
}

public class foo
{
public int bar //property
{
get
{
return 0;
}
}
}

The simplified example above doesn't do justice to the possibilities of
properties. For example, let's say you create a class that draws a
rectangle. You could create a read-only property of that class that
returns the area of the rectangle, by multiplying the length times the
width.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.
"Scott M." <s-***@nospam.nospam> wrote in message
news:eP**************@TK2MSFTNGP14.phx.gbl...
You've got it.

Properties are nothing more than variables that are specific to an
object.
"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:uc**************@TK2MSFTNGP15.phx.gbl...
Hi All,

Being a classic ASP programmer, I'm trying to get to grips with OOP,
specifically using classes.

I have setup my class with various properties, so far so good. What I
dont
quite get is the logic of using the properties.

E.g. If I want to get the RoadName property of my address class into a
database, do I do something like this...

Public function saveToDB()
strSQL = "Insert into TblName RoadName Values " &
address.RoadName
bla bla bla....run the sql here!
End Function

Also, if I want to get a specific address from my DB and create an
address
object from it, do I do something like this?

Public Function GetAddress(byval RoadName as String)
strsql = "select roadname fromtblname where roadname = " &
roadname
bla bla...run the SQL
address.roadname = dr("roadname")
End Function

I guess I just need someone to confirm my thinking is right on this, or
if
not, point me in the right direction! :)

Thanks,
Simon.

--
I am using the free version of SPAMfighter for private users.
It has removed 2173 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!



Nov 19 '05 #5
Thanks Kevin/Scott. You've both helped me understand this.

Nov 19 '05 #6

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

Similar topics

1
by: Steven Lien | last post by:
I wrote a simple vector class that can store Cards, and my question is if i had Card class, should i "new" it to store into vector , or simply use copy structure?. if i need the vector class to be...
1
by: Victor Hannak | last post by:
I have two classes derived from a base class. The two derived classes each utilize a structure that is slightly different from one another. i.e. DerivedClass1: struct NodeStruct { float...
7
by: Ben | last post by:
Hi all, I'm not yet good at thinking the right way in c++ so although I could solve this problem, I'm not sure if they way I'm thinking of is the best way to do it. I need a data type or class...
1
by: shunah | last post by:
hello. In an app I'm building, there are two different kinds of memos, family memos and individual memos. Right now I have a single form that I using in four slightly different ways: 1. add a...
5
by: Stephen Russell | last post by:
In the past public void has worked. But I need to return an XMLDocument, and this class needs a string param for the SP to call. public void makeXML (string lcStatement) wont allow me to return...
5
by: Nick Foster | last post by:
I have created an abstract base class and several classes that inherit it. i.e. Public MustInherit Class Person Public Property Name ...... End Property Public MustOverride Sub Add() End...
9
by: easy | last post by:
I start off with an interface class that has no data members and a handful of virtual functions. First Question: is that allowed ? I then derived from this class and it gets included into...
3
by: Peskov Dmitry | last post by:
Hi, What is the memory layout of an object, and the derived object. For example : class A { private: int prv_data; protected: int pro_data;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.