General OOP Technique Question

  • Thread starter Thread starter Ivan Weiss
  • Start date Start date
I

Ivan Weiss

I am designing a class to represent an item in a database (containing
model's of products). I need to display a listing of all of these items
in a listview to be displayed to the user (so they can select, edit, or
delete the item). To follow the right way cause I am new and learning
OOP should I create a function within the class to return all items or
in a module or in the calling form itself? I figured it shouldnt go in
the class itself because the object should represent one item not the
whole collection so I was a bit confused.

Any help is appreciated.

-Ivan
 
Ivan... Seriously you have to get a book on all this. You'll save yourself
countless hours of wondering if you read about how people have solved these
exact problems for close to 20 years. This BTW, doesn't mean you have to
pick up the nearest VB.Net book. I recommend to anybody to read about
"object-orientation" as a concept and not as a bunch of syntax that has to
be memorized.

So to answer your question. You have a Product class (let's say) which you
can use to produce a product object. What you need now is a Products class
from which you can produce a collection of Product objects.

If you want, post the code from your Product class.

And a book will help... alternatively it's going to be a constant uphill
battle.
Tom
 
Can you recommend any good easy to read OOP books? I find that most
reference/instructional books are easy to understand what the author is
saying but use in my own projects since I am basically a
novice/intermediate programmer.

Thanks,

-Ivan
 
I do have a VB.NET book that kind of covers it all but I to be honest
have just been using it as a reference as it does not contain concepts
for object oriented design. You are right I do need to read up on it
but to be honest this app is being written on my spare time on my own
and I work a full time job and also am going to school so needless to
say I really dont have too much time to be reading any other books than
the textbooks from class. I do appreciate your help.

My items class right now is just a class listing all of the data
members:

Public Class Items

#Region " Data Members "

Private myID As Integer
Private myModel As String
Private myManufacturer As String
Private myDescription As String
Private mySpecification As String
Private myElectric_Info As Integer
Private myConnectionType As String
Private myVolts As String
Private myPhase As String
Private myAmps As String
Private myKWs As String
Private myHP As String
Private myElectric_AFF As String
Private myElectric_Remarks As String
Private myPlumbing_Info As Integer
Private mySteam As String
Private mySteam_AFF As String
Private myGas As String
Private myGas_AFF As String
Private myBTUs As String
Private myHW As String
Private myHW_AFF As String
Private myCW As String
Private myCW_AFF As String
Private myDrain As String
Private myDrain_AFF As String
Private myIDrain As String
Private myIDrain_AFF As String
Private myPlumbing_Remarks As String

#End Region

End Class

However, I did start coding another class which I need to revise and
correct some OOP mistakes but here it is if you want to look it over:

Imports System.Data
Imports System.Data.OleDb

Public Class Project

Private myProjectID As Integer
Private myCustomerID As Integer
Private myProjectStatus As String

Public Sub New(ByVal argCustomerID As Integer)
myCustomerID = argCustomerID
End Sub

Public ReadOnly Property ProjectID() As Integer
Get
Return (myProjectID)
End Get
End Property

Property CustomerID() As Integer
Get
Return (myCustomerID)
End Get
Set(ByVal Value As Integer)
myCustomerID = Value
End Set
End Property

Public ReadOnly Property ProjectStatus() As String
Get
Return (myProjectStatus)
End Get
End Property

Public Function addProject() As Boolean
Dim myDatabase As New Database
Dim mySqlString As String

If myCustomerID = Nothing Then
MsgBox("You must select a customer first. Adding a project
failed!", MsgBoxStyle.Exclamation, "Project Add Failed")
Return False
Else
mySqlString = "INSERT INTO Projects(Company_ID,Status)
VALUES ('" & myCustomerID & "','Closed')"
myDatabase.Modify(mySqlString)
myDatabase.Dispose()
Return True
End If
End Function

Public Function deleteProject(ByVal argProjectID As Integer) As
Boolean
Dim myDatabase As New Database
Dim mySqlString As String

If argProjectID = Nothing Then
MsgBox("You must select a project first. Deleting a project
failed!", MsgBoxStyle.Exclamation, "Project Deletion Failed")
Return False
Else
mySqlString = "DELETE FROM Projects WHERE Project_ID = " &
argProjectID
myDatabase.Modify(mySqlString)
myDatabase.Dispose()
Return True
End If
End Function

End Class

-Ivan
 
I'll try to respond to both messages here... first as for a book... anything
that isn't language specific. Find an old SmallTalk book, perhaps "Inside
SmallTalk" by Wilf R. LaLonde. Or "Object-Oriented Analysis" by Coad and
Yourdon or "Object Oriented Design With Applications" by Grady Booch or
"Essays on Object-Oriented Software Engineering" by Edward Berard. They are
all probably out of print. So find essays or other books written by these
authors. Most of the books I've mentioned are from around 1990.

My point is (always) that this stuff wasn't invented with VB.Net so don't
limit yourself to this one implementation's view of OOP.

Ivan Weiss said:
but to be honest this app is being written on my spare time on my own
and I work a full time job and also am going to school so needless to
say I really dont have too much time to be reading any other books than
the textbooks from class.

As the old joke goes... if you don't have the time to do it right how do you
find the time to do it all over again?
My items class right now is just a class listing all of the data
members:

Public Class Items

#Region " Data Members "

Private myID As Integer
Private myModel As String
Private myManufacturer As String
.... electrical, steam, plumbing and gas properties snipped
#End Region

End Class

Recall we spoke about the "my" naming convention before? This is what I
mean... you could add a few names and addresses, the current date and time,
MyFavoriteMovie and a spot for FreeDiskSpace and you wouldn't need another
class defined again. :-)

A book would not only avoid suggesting you approach the solution this way it
would devote a chapter specifically to why you shouldn't. It's an
"everything and the kitchen sink" class... where would you build up from
here?
However, I did start coding another class which I need to revise and
correct some OOP mistakes but here it is if you want to look it over:

It's going to be tough... again you have to read something. In this case
you might want to find short examples in VB.Net. You won't find a single
one which pops a modal message box up in the middle of class method. At
least I'm betting you won't.

I think you know I'm not trying to cause you grief, I'm honestly trying to
save you hours of frustration. I can see it in your examples that 40
precious hours from now you will simply have to start over. In the long run
you are better off stopping now, reading a bunch more and if you'd like to
take my advice, writing a non-database application to start. Get the
concepts down without having to worry yourself about database access on top
of everything else. For now I leave you with the opening paragraphs of a
book I wrote on software application development...

<begin quote>
There is a big difference between computer programming and computer
application development. Programming consists primarily of controlling the
computer through computer language constructs. Programming is the process of
combining algorithms and data structures to perform a given task. This
relationship is, in fact, the title of a classic book by Niklaus Wirth
called Algorithms + Data Structures = Programs (Prentice-Hall, 1976).

As a result of college courses or through diligent self­study, you can
eventually learn what a variable is, how to write a FOR... NEXT loop, and
when to use stacks, queues and linked-lists. After some practice in BASIC,
Pascal, C, dBASE, FoxPro or Clipper, Ada, Lisp, Forth or any of a dozen
other computer languages, you will have harnessed the fundamentals and can
honestly claim that you program in that language.

However, designing and more importantly completing sophisticated
applications involves additional skills that are almost never taught in
school. Some programmers discover the secrets of developing computer
applications over time, but developing applications remains for many an
elusive challenge, a contest or even a battle between the programmer and the
language, with the computer in the role of referee.

Application development is computer programming and then some. This point
helps explain why I'm asked the following question more often than any
other: "Where do I begin?"
<end quote>
 
Hi Ivan,

Only one addition to Tom while I hope I am not killing all the good work Tom
has done for you.

OOP is not a goal, good performce, friendly for the client, reusability,
readability, cooperate working should be some of the goals.

One of the routes to reach that is today is using OOP.

I tell this because I have seen that for some people OOP goes for the result
and then all those things I told are sometimes worse than without OOP.

But for the rest, follow the avices from Tom,

Cor
 
You make a good point and are actually very right about the re-coding.
I have already several times re-written pieces of code completely to
follow closer to OOP techniques. I will look into a book and start from
there.

-Ivan
 
Back
Top