473,386 Members | 1,705 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,386 software developers and data experts.

OOP Principles

Hello,

I'm getting more and more familiar every day with VB.NET and I'm trying
right now to create custom classes for one of my applications. I've got some
experience with OOP, but I'm not sure exactly how to lay these classes out.
The questions are probably pretty basic for someone with experience so let's
just jump right in, shall we? :)

Scenario: I have a web application that allows users to search for homes for
sale, as well as allowing my clients to administer those homes. I'm creating
a class called RentalProperty. It has properties such as Address, City,
State, Beds, Baths, SquareFootage, IsFeaturedProperty, etc. You get the
idea. However, I also want to have a property "Amenities" which would return
a custom collection of an Amenity object (which I'm also creating). The
amenities are things like "Washer/Dryer", "Pool", etc.

My SQL Server database has the following tables:

Properties (property_id, address, city, state, etc)
Amenities (amenity_id, name)
Properties_Amenities (property_id, amenity_id)

So to this point, creating the RentalProperty class has been pretty simple.
I've also created a simple Amenity class with the following properties: ID,
Name. I also have an AmenityCollection class which returns a collection of
Amenity objects. So...here are my questions:

1) I have the Amenities property of the RentalProperty class set up like
this:

Private p_Amenities As AmenityCollection
Public Property Amenities() As AmenityCollection
Get
Return p_Amenities
End Get
Set(ByVal Value As AmenityCollection)
p_Amenities = Value
End Set
End Property

Here is the AmenityCollection code:

Public Class AmenityCollection : Inherits System.Collections.CollectionBase
Default Public ReadOnly Property Item(ByVal intIndex As Integer) As
Amenity
Get
Return CType(list.Item(intIndex), Amenity)
End Get
End Property

Public Sub Add(ByVal objItem As Amenity)
list.Add(objItem)
End Sub

Public Sub Remove(ByVal intIndex As Integer)
Try
list.RemoveAt(intIndex)
Catch exc As Exception
Throw New ArgumentOutOfRangeException
End Try
End Sub
End Class

1 cont'd) However when I am using a RentalProperty object, and I type
RentalProperty.Amenities. (and wait for intellisense in Visual Studio), it
doesn't show an "Items" property, so that I can do this: For Each objAmenity
As Amenity in RentalProperty.Amenities.Items. Maybe I have the collection
class set up incorrectly? The question is: what's the best way to set this
up so that the "Amenities" property of my RentalProperty returns a usable,
iterable collection of Amenity objects?

2) The Amenities class/collection is really not going to be utilized too
much other than as a property of the RentalProperty object. I'll need to be
able to populate the collection with the current amenities for a given
property, PLUS I want to be able to add/remove amenities (when they're
editing the property in the admin screen) and then call a .Save method to
save the current amenities back to the database. Now, should the .Save
method should be a member of the AmenityCollection class? That doesn't seem
right to me, but by the same token, adding .Save to the Amenity class
doesn't seem right since that's dealing with just one amenity, not posting
the entire set of amenities back to the database. Any clarification here?

That should do it for now! ;-) I'm sure I'm just missing a few key pieces of
knowledge and once I figure these few things out, things are going to be
looking good! Any explanations or references to URLs for further information
are appreciated!

Thanks,

Scott
Nov 21 '05 #1
2 1052
Scott,

The problem with creating classes for webapplication is that they are
stateless, which means that for every post the needed objects have to be
instanced. You see the problem before you?

A shared class is as well no solution because that is used by the
application. What means for all sessions together as one shared class until
there are no sessions anymore active. However when you have data that should
be for everybody without any client selection or value, than does that fit.

When you use a dataset (which is of course as well an object instanced from
a class) than you can nicely store that in a session, and get it easily back
when there is a postback in the way you readed it before the post. (When you
do a reread you have the change that there is been changed something by
somebody else)

I hope this helps a little bit?

Cor
Nov 21 '05 #2

Try Building your solution first. Sometimes intellisense will not instantly
see the new properties of the class until you do this. I copied your code
into RentailProperty Class and Created an AmenityCollection property.
Switched back to the Main Form, create a new instance of the Rental Property
and then looked at its members. The Items property did not instantly show in
intellisense, however as soon as I did a build this worked fine and the Item
property appeared in the list of members
HTH
Nov 21 '05 #3

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

Similar topics

0
by: steven.bagnall | last post by:
Hi, I have recently bought the old/green dragon book "Principles Of Compiler Design" (1977) - although mine appears to be pink! It has questions at the end of every chapter, but doesn't...
22
by: lechequier | last post by:
Let's say I define a list of pairs as follows: >>l = Can anyone explain why this does not work? >>h = {}.update(l) and instead I have to go: >>h = {} >>h.update(l) to initialize a...
0
by: andrew lowe | last post by:
Hi We have windows application and have created our own custom principle & identity objects that implement IPrinciple and IIdentity. When a user logs into our system we set the threads principle...
1
by: Mr Gordonz | last post by:
Hi All, I am building a site that will be used by different types of users, and each type of user will do similar, but substantially different, things. My question is a general one: what is the...
2
by: Silent Ocean | last post by:
Hi 1. I am in process of designing N-Tier Application using ASP.NET. Can anyone guide me the right material or microsoft guidelines document which I can used in designing the N-Tier application....
11
by: Jordan Bowness | last post by:
I'm trying to develop a bunch of classes and want to do it the right way. Say I have 5 classes: City, Neighborhood, NeighborhoodCollection, House, HouseCollection
8
by: cat | last post by:
I had a long and heated discussion with other developers on my team on when it makes sense to throw an exception and when to use an alternate solution. The .NET documentation recommends that an...
0
by: crm-tutorial | last post by:
Service-Oriented Architecture(SOA) - Principles & Practice (October 2006) The Principles of SOA,Loosely-Coupled Architecture,The SOA Solution - How it Works,The iBOLT Flow Editor, Composite...
1
by: zhi.yang.pek | last post by:
would you give me a copy or the link?Thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.