473,397 Members | 2,116 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,397 software developers and data experts.

OOP: Best practice?

I have a "Inventory" Object that contains the product and all its fields.

The problem is that I am getting soooooo many functions under main Inventory
class so it becames impossible to initalize a new programmer into this code.

For sample, I have Add_AllowAccess, Add_DisallowAccess, Remove_AllowAccess,
Remove_DisallowAccess, Get_AllowAccess, Get_DisallowAccess (this is only a
sample)

I would really like
Inventory.Access.Allow.Add
Or
Inventory.Access.Add(Enum.Allow...)
(sometimes however one simular function might need diffrent parameters then
the other...)
My questions are

1. Is the best practice to do it the way I described above
(Inventory.Access.Add etc)

2. Add_AllowAccess() needs access to Inventory Object, Should I create
subclasses only containing methods, and use a Parent object that points to
Main Inventory class?

3. Or is there another way to do this all together?

- Fredrik
Nov 21 '05 #1
8 1762
Fredrik Melin wrote:
I have a "Inventory" Object that contains the product and all its fields.

For sample, I have Add_AllowAccess, Add_DisallowAccess, Remove_AllowAccess,
Remove_DisallowAccess, Get_AllowAccess, Get_DisallowAccess (this is only a
sample)
1. Is the best practice to do it the way I described above
(Inventory.Access.Add etc)
Since you are talking about permissions, and this seems to be a somewhat
large project, I prefer to use an actual permissions object, which may
or may not be combined with the user object. Then, if the user has
permission to do something with the Inventory object, then he does it.

Because I have been programming since the days of bit flags, that is
what I sometimes use, but that isn't necessary. The user or permissions
object can then be queried, in the form of a property, for a permission
which can return true, false, or some level ( some systems allow for a
lesser user to view, but not make changes ). The benefit of keeping
permissions as a class is that you can then just add more permissions to
it for other areas of the applicaiton, rather than writing permissions
aspects to each section.

As far as best practice, my experience is the method that makes for less
complication, ease of re-use, less bloated code, and faster execution is
what I adopt as the best practice.

Tom
2. Add_AllowAccess() needs access to Inventory Object, Should I create
subclasses only containing methods, and use a Parent object that points to
Main Inventory class?

3. Or is there another way to do this all together?

- Fredrik

Nov 21 '05 #2
Yes, its a very large project.

This is just a sample of some of the functions, this access is actually
which customers has the access to see the product on the webserver.

But we have tons of other types of functions, like

Add_SalesStatistics
Remove_SalesStatistics
Update_SalesStatistics
.....
and so on, its functions that are used in a certain conditions, could be
when you call .Invoice on the Invoice object

but still, it cloggs up the code if you look at it as a "external"
programmer.

Sure I can rename it and use enum for Add/Remove/Update, but then what Shall
I name it?

"tomb" <to**@technetcenter.com> wrote in message
news:5P***************@bignews7.bellsouth.net...
Fredrik Melin wrote:
I have a "Inventory" Object that contains the product and all its fields.

For sample, I have Add_AllowAccess, Add_DisallowAccess,
Remove_AllowAccess, Remove_DisallowAccess, Get_AllowAccess,
Get_DisallowAccess (this is only a sample)
1. Is the best practice to do it the way I described above
(Inventory.Access.Add etc)

Since you are talking about permissions, and this seems to be a somewhat
large project, I prefer to use an actual permissions object, which may or
may not be combined with the user object. Then, if the user has
permission to do something with the Inventory object, then he does it.
Because I have been programming since the days of bit flags, that is what
I sometimes use, but that isn't necessary. The user or permissions object
can then be queried, in the form of a property, for a permission which can
return true, false, or some level ( some systems allow for a lesser user
to view, but not make changes ). The benefit of keeping permissions as a
class is that you can then just add more permissions to it for other areas
of the applicaiton, rather than writing permissions aspects to each
section.

As far as best practice, my experience is the method that makes for less
complication, ease of re-use, less bloated code, and faster execution is
what I adopt as the best practice.

Tom
2. Add_AllowAccess() needs access to Inventory Object, Should I create
subclasses only containing methods, and use a Parent object that points to
Main Inventory class?

3. Or is there another way to do this all together?

- Fredrik

Nov 21 '05 #3
And to add on to this

I also have

Add_OrderStatistics
Remove_OrderStatistics
Update_OrderStatistics

So Inventory.Statistics.Order and Inventory.Statistics.Sales would have been
nice :)
"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:1p********************@giganews.com...
Yes, its a very large project.

This is just a sample of some of the functions, this access is actually
which customers has the access to see the product on the webserver.

But we have tons of other types of functions, like

Add_SalesStatistics
Remove_SalesStatistics
Update_SalesStatistics
....
and so on, its functions that are used in a certain conditions, could be
when you call .Invoice on the Invoice object

but still, it cloggs up the code if you look at it as a "external"
programmer.

Sure I can rename it and use enum for Add/Remove/Update, but then what
Shall I name it?

"tomb" <to**@technetcenter.com> wrote in message
news:5P***************@bignews7.bellsouth.net...
Fredrik Melin wrote:
I have a "Inventory" Object that contains the product and all its fields.

For sample, I have Add_AllowAccess, Add_DisallowAccess,
Remove_AllowAccess, Remove_DisallowAccess, Get_AllowAccess,
Get_DisallowAccess (this is only a sample)
1. Is the best practice to do it the way I described above
(Inventory.Access.Add etc)

Since you are talking about permissions, and this seems to be a somewhat
large project, I prefer to use an actual permissions object, which may or
may not be combined with the user object. Then, if the user has
permission to do something with the Inventory object, then he does it.
Because I have been programming since the days of bit flags, that is what
I sometimes use, but that isn't necessary. The user or permissions
object can then be queried, in the form of a property, for a permission
which can return true, false, or some level ( some systems allow for a
lesser user to view, but not make changes ). The benefit of keeping
permissions as a class is that you can then just add more permissions to
it for other areas of the applicaiton, rather than writing permissions
aspects to each section.

As far as best practice, my experience is the method that makes for less
complication, ease of re-use, less bloated code, and faster execution is
what I adopt as the best practice.

Tom
2. Add_AllowAccess() needs access to Inventory Object, Should I create
subclasses only containing methods, and use a Parent object that points
to Main Inventory class?

3. Or is there another way to do this all together?

- Fredrik


Nov 21 '05 #4
Frederik,

We see off course only a part of your code, however don't you have a
SalesStatics or AllowAcces Class.

Than it could be as this.
\\\
Public Class AllowAccess
Public Sub New
mAllow = false 'only for the sample normal this is not necessary
End Sub
private boolean mAllow
public property Allow as Boolean
Get
mAllow = false
End Get
Set(ByVal Value As Boolean)
return mAllow
End Set
End Property
///
And than while in your whatever class is the same but than
public class Whatever
private mAllowAccess as AllowAcces
public property AllowAccess as AllowAccess
bla bla
end Class
.....
whatever.AllowAccess = New AllowAcces
whatever.AllowAccess.Allow = true
and to remove it
whatever.AllowAccess = nothing
I hope this helps,

Cor
Nov 21 '05 #5
Here is some sample code of my Add_SalesStatistics

Public Function Add_SalesStatistics(ByVal quantity As Long, ByVal
invoiceRowID As Long, ByRef dbTrans As SqlClient.SqlTransaction) As Boolean
Dim dbConn As SqlClient.SqlConnection
Dim cmSQL As SqlClient.SqlCommand
Try

dbConn = dbTrans.Connection
cmSQL = New SqlClient.SqlCommand("", dbConn)
cmSQL.Connection = dbConn
cmSQL.Transaction = dbTrans

cmSQL.CommandText = "INSERT INTO INVENTORY_SALES_STATISTICS
(PRODUCT_ID, INVOICE_ROW_ID, QUANTITY, DATE_SOLD) VALUES (@PRODUCT_ID,
@INVOICE_ROW_ID, @QUANTITY, @DATE_SOLD)"
cmSQL.Parameters.Add("@PRODUCT_ID", SqlDbType.VarChar).Value =
sProduct_ID
cmSQL.Parameters.Add("@INVOICE_ROW_ID", SqlDbType.Decimal).Value
= invoiceRowID
cmSQL.Parameters.Add("@QUANTITY", SqlDbType.Decimal).Value =
quantity
cmSQL.Parameters.Add("@DATE_SOLD", SqlDbType.DateTime).Value =
DSO.Globals.SystemFunctions.SQLServerDate.Date
If cmSQL.ExecuteNonQuery() > 0 Then Return True

Catch ex As Exception
DSO.Globals.ErrReport.RegisterError(ex, , Me)
Finally
cmSQL.Dispose()
End Try
End Function
As you see, its a little more complex that I can solve in a property, It
also address code from Main inventory class (sProduct_ID)

So my idea is maybe to do

Public Class Inventory
Private mclsStatistics as clsStatistics
Public Reaonly Property Statistics as clsStatistics
Get
If mclsStatistics Is Nothing Then mclsStatistics = New
clsStatistics(Me)
End Get
Return mclsStatistics
End Property
Public Class clsStatistics
Private mParent as Inventory

Public Sub New (ParentObject as Inventory)
mParent = ParentObject
End Sub

Public Function Add(enum SalesOrOrder, invoiceRowID......) as
Boolean
... code
End Function

End Class
....
End Class

Which would get me Inventory.Statistics.Add

but is that the correct way to do it?

- Fredrik
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Frederik,

We see off course only a part of your code, however don't you have a
SalesStatics or AllowAcces Class.

Than it could be as this.
\\\
Public Class AllowAccess
Public Sub New
mAllow = false 'only for the sample normal this is not necessary
End Sub
private boolean mAllow
public property Allow as Boolean
Get
mAllow = false
End Get
Set(ByVal Value As Boolean)
return mAllow
End Set
End Property
///
And than while in your whatever class is the same but than
public class Whatever
private mAllowAccess as AllowAcces
public property AllowAccess as AllowAccess
bla bla
end Class
....
whatever.AllowAccess = New AllowAcces
whatever.AllowAccess.Allow = true
and to remove it
whatever.AllowAccess = nothing
I hope this helps,

Cor

Nov 21 '05 #6
Frederik,

Did you had a look at the standard generated code. Maybe is a problem that
it is in version 2.0 more logical and completely different done.

However, with 1.1 if you just try this to do. (Probably you know all however
when not)

Open a project and add an item component
Use for that the a dataadapterwizard from the toolbox
After doing all what there is needed (everything standard, change nothing
Right click on than on the icon dataadapter and click on generate dataset

In the component you see than all code generated when you open the plus.

If you in solution explorer open tell "show all files in top" than you see a
completly strongly typed class generated with the name dataset1.vb

You can open it and look to it, it are just all kind of OOP stronly typed
classes generated.

Not to use it however to get the idea how it is done.

I hope this helps,

Cor
Nov 21 '05 #7
Thanks, very nice tip!
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl...
Frederik,

Did you had a look at the standard generated code. Maybe is a problem that
it is in version 2.0 more logical and completely different done.

However, with 1.1 if you just try this to do. (Probably you know all
however when not)

Open a project and add an item component
Use for that the a dataadapterwizard from the toolbox
After doing all what there is needed (everything standard, change nothing
Right click on than on the icon dataadapter and click on generate dataset

In the component you see than all code generated when you open the plus.

If you in solution explorer open tell "show all files in top" than you see
a completly strongly typed class generated with the name dataset1.vb

You can open it and look to it, it are just all kind of OOP stronly typed
classes generated.

Not to use it however to get the idea how it is done.

I hope this helps,

Cor

Nov 21 '05 #8
You are missing the basic rules of encapsulation. There are 2 guidelines
that I like to follow. They are:

1) Low Coupling:
Coupling is a measure of how strongly one class is connected to, has
knowledge of, or relies on other classes in the system. You should try and
minimize this.

High Cohesion:
Cohesion is a measure of how strongly related and focused the responsibility
of a class is. You want to make sure your the methods you add remain
cohesive to what the class is supposed to encapsulate.

Picking the right classes that follow these rules and solve your problems is
the hard part. There are numerous books out there describing multiple
techniques to actually do this. These processes can get highly involved.
You typically can't just start coding and get to a good object oriented
design. Instead you need to plan ahead. UML and case tools are designed to
help you do this. Think of the analogy of building a house. You typically
don't just grab wood, hammer, and nails and have at it. Instead, you need to
draw and plan the entire structure first. Start building and then re-adjust
your plans when issues arise. Software is the same.

"Fredrik Melin" wrote:
I have a "Inventory" Object that contains the product and all its fields.

The problem is that I am getting soooooo many functions under main Inventory
class so it becames impossible to initalize a new programmer into this code.

For sample, I have Add_AllowAccess, Add_DisallowAccess, Remove_AllowAccess,
Remove_DisallowAccess, Get_AllowAccess, Get_DisallowAccess (this is only a
sample)

I would really like
Inventory.Access.Allow.Add
Or
Inventory.Access.Add(Enum.Allow...)
(sometimes however one simular function might need diffrent parameters then
the other...)
My questions are

1. Is the best practice to do it the way I described above
(Inventory.Access.Add etc)

2. Add_AllowAccess() needs access to Inventory Object, Should I create
subclasses only containing methods, and use a Parent object that points to
Main Inventory class?

3. Or is there another way to do this all together?

- Fredrik

Nov 21 '05 #9

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

Similar topics

8
by: Berislav Lopac | last post by:
I have a some experience in OOP, primarily with Java and JavaScript, and a little with PHP4. I have just checked some texts about upcoming PHP5 features, and particularly the OOP ones, and there is...
75
by: projecktzero | last post by:
I know this might not be the correct group to post this, but I thought I'd start here. A co-worker considers himself "old school" in that he hasn't seen the light of OOP.(It might be because...
56
by: Xah Lee | last post by:
What are OOP's Jargons and Complexities Xah Lee, 20050128 The Rise of Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...)...
77
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
5
by: altergothen | last post by:
I'm currently doing a course in C# programming fundamentals. Please will you check and comment on the following assignment: Assignment: Create a simple calculator prgram that illistrates good OOP...
15
by: John Salerno | last post by:
Ok, I have a new random question for today -- feel free to ignore and get back to your real jobs! :) Anyway, I'm creating a GUI (yes, all part of my master plan to eventually have some sort of...
12
by: RSH | last post by:
I am still trying to grasp the use of real world Objects and how to conceptualize them using a business scenerio. What I have below is an outline that I am wrestling with trying to figure out a...
7
by: RSH | last post by:
I am struggling with a concept I'm not really finding a lot of in depth articles on but Im sure others have had similar issues. What is the best practice when it comes to persisting custom...
14
by: mesut | last post by:
hi colleagues, I don't know if this is the right group for but it's in C# so I try. I have a #3 procedural function called GetInfo.. and those are 3 overloaded methods. I would like to use the...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.