Structure declaration - use of structure

D

Douglas Buchanan

Newbie to donnet

This is an example of a structure given in vs.net help

============================
Private Structure Employee
Public GivenName As String ' This employee's given name.
Public FamilyName As String ' This employee's family name.
Public Extension As Long ' This employee's telephone extension.
Private Salary As Decimal ' This employee's annual salary.
Public Sub GiveRaise(Raise As Double) ' Raise this employee's
salary.
Salary *= Raise
End Sub
Public Event ReviewTime() ' This employee must be reviewed.
End Structure
============================
(I come from database application backgroud.)

The example given above stores emplyee information. Why bother storing
employee information in a structure if you are going to later put into
a database anyway. Why not just put it directly into a database. Or is
the example above just an impractical example?

Can someone give me an example for the use of a structures that
illustrates what its advantages are.
 
S

Sahil Malik

Why put things in a structure when they could be perfectly stored in a
database? Because simply a database is not available everywhere.

Say you were to write a webservice that gives you back an arraylist of
employees. The webservice is called by an ASP.NET page, which then renders
to a browser; maybe even a WAP browser on a Pocket PC. Even though you could
possibly have a SQL Server running there; you could not guarantee access to
it, you could not guarantee it's existence, not to mention you cannot
guarantee every pocket pc with a pocket dba to maintain that sql server.

It's just an alternate representation of the data to make it more portable.
Another word for this is "Business objects", so Employee structure could be
a business object, customer/order/address etc. could be other business
objects. And these have the ability to live on their own, and describe
themselves completely without relying on any other entity. Many of these can
be serialized and sent from one end of the wire to another; like star trek
transporter even. Or some of these can be shallow serialized like the movie
Matrix (proxy stays on one machine and the stub acts on another machine; one
dies the other croaks too). The main theme being, they can do all this
without any setup, or need for any additional software. Certainly not a
heavy duty s/w like a RDBMS.

Hella exciting stuff man .. welcome to programming :). Further reading -
Structure Vs. Class in .NET.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 
D

Douglas Buchanan

Sahil,

Thank you for the very thorough answer.

Sahil Malik said:
Why put things in a structure when they could be perfectly stored in a
database? Because simply a database is not available everywhere.

Say you were to write a webservice that gives you back an arraylist of
employees. The webservice is called by an ASP.NET page, which then renders
to a browser; maybe even a WAP browser on a Pocket PC. Even though you could
possibly have a SQL Server running there; you could not guarantee access to
it, you could not guarantee it's existence, not to mention you cannot
guarantee every pocket pc with a pocket dba to maintain that sql server.

It's just an alternate representation of the data to make it more portable.
Another word for this is "Business objects", so Employee structure could be
a business object, customer/order/address etc. could be other business
objects. And these have the ability to live on their own, and describe
themselves completely without relying on any other entity. Many of these can
be serialized and sent from one end of the wire to another; like star trek
transporter even. Or some of these can be shallow serialized like the movie
Matrix (proxy stays on one machine and the stub acts on another machine; one
dies the other croaks too). The main theme being, they can do all this
without any setup, or need for any additional software. Certainly not a
heavy duty s/w like a RDBMS.

Hella exciting stuff man .. welcome to programming :). Further reading -
Structure Vs. Class in .NET.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top