473,474 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OOP and C#: Too much objects make me unhappy, but what can I do??

Hi,
I'm doing my first big project in C# and I'm stuck with a problem that
I believe has a simple and efficient solution for it (I just haven't
bumped into it yet...). The concept is the following:

//Users manage clients. When the system creates the client it must
fetch the information from the DB and allow some modifications:

Client client = new Client("test");
MasterAccount ma = new MasterAccount(1324651);
client.MasterAccount = ma;
PurchaseItems pi = client.MasterAccount.GetPurchasedItems();
FillListview(pi);

// when a user selects a line in the listview, he must have the
possibility to split each line into two or more lines:

pi[0].Subitem[0..n]

// Each Subitem contains in turn two variables that will in turn be
instanced into two new classes:

Subitem si = pi[0].Subitem[0];
si.TypeA = new Type();
si.TypeB = new Type();

//TypeA and TypeB are of the same type. But in turn contain more class
variables inside

si.TypeA.SubType0
si.TypeA.SubType1
si.TypeA.SubType2
si.TypeA.SubType3

//The SubTypes contain only bool variables and a method.

My problem is that this is a representation in a "object oriented way"
(I think) of what the user sees on screen, but in terms of
calculations and memory comsumption it is not efficient, although it
is flexible enough to make future modification easy.

The problem is that now I'm stuck with this concept, and although I'm
trying to model other solutions in UML, I am not getting anywhere in
order to improve this. A friend suggested storing the values in arrays
and looping through it in order to calculate the values but I dislike
the idea due to (in my opinion) complicated implementation and the
fact that the code becomes much more difficult to understand and
modify in the future.

Please correct me if I'm wrong, through ideas in, whatever...
I welcome all suggestions.

PS. I thought about using patterns, like the singleton pattern or the
flyweight pattern, however I haven't seen real live examples and so I
don't understand how I could use them in my application.

Thank in advance
Hugo
Nov 16 '05 #1
4 1449

Could you explain briefly what you're trying to do, rather than explaining
how you're trying to do it...
From evaluating a problem, we can the provide recommendations, opinions and
ideas as to where you could go.

Thanks

Dan.

"hufel" <hu*********@yahoo.com> wrote in message
news:5c**************************@posting.google.c om...
Hi,
I'm doing my first big project in C# and I'm stuck with a problem that
I believe has a simple and efficient solution for it (I just haven't
bumped into it yet...). The concept is the following:

//Users manage clients. When the system creates the client it must
fetch the information from the DB and allow some modifications:

Client client = new Client("test");
MasterAccount ma = new MasterAccount(1324651);
client.MasterAccount = ma;
PurchaseItems pi = client.MasterAccount.GetPurchasedItems();
FillListview(pi);

// when a user selects a line in the listview, he must have the
possibility to split each line into two or more lines:

pi[0].Subitem[0..n]

// Each Subitem contains in turn two variables that will in turn be
instanced into two new classes:

Subitem si = pi[0].Subitem[0];
si.TypeA = new Type();
si.TypeB = new Type();

//TypeA and TypeB are of the same type. But in turn contain more class
variables inside

si.TypeA.SubType0
si.TypeA.SubType1
si.TypeA.SubType2
si.TypeA.SubType3

//The SubTypes contain only bool variables and a method.

My problem is that this is a representation in a "object oriented way"
(I think) of what the user sees on screen, but in terms of
calculations and memory comsumption it is not efficient, although it
is flexible enough to make future modification easy.

The problem is that now I'm stuck with this concept, and although I'm
trying to model other solutions in UML, I am not getting anywhere in
order to improve this. A friend suggested storing the values in arrays
and looping through it in order to calculate the values but I dislike
the idea due to (in my opinion) complicated implementation and the
fact that the code becomes much more difficult to understand and
modify in the future.

Please correct me if I'm wrong, through ideas in, whatever...
I welcome all suggestions.

PS. I thought about using patterns, like the singleton pattern or the
flyweight pattern, however I haven't seen real live examples and so I
don't understand how I could use them in my application.

Thank in advance
Hugo

Nov 16 '05 #2
I'll do my best to explain:

The application main purpose is to retrieve information regarding
purchased items by a client. Each client has a masteraccount. He uses
this MasterAccount to purchase items. This is were I begin the hard
part. I must read the items, show them in a listview and allow the
user of my application to split each item into two or more subItems.
Each SubItem contains two more pieces of information that I simply
called 'TypeA' and 'TypeB'. When the user starts working the
information regarding 'TypeA', he is filling information regarding the
client divided into 4 'blocks' that I called SubTypes. Each SubType
contains several boolean variables. I need to read the information
contained in these boolean variables, multiply it by a factor directly
related to each variable and by the amount spent on the original item.
The result is calculated at the subItem level. These values are stored
inside a sql server 2000 db.

Pseudocode:

bvA = Client.MasterAccount.PurchasedItems[].Subitems[].TypeA.SubType0.BoolVarA;
foreach (purchasedItem)
foreach (SubItem)
TypeA.CalcValues {
Calc_SubType0 {
bvA(0/1) * Factor_bvA * Amount($)
bvB(0/1) * Factor_bvB * Amount($)
bvC(0/1) * Factor_bvC * Amount($)
}
Calc_SubType1 {
bvD(0/1) * Factor_bvD * Amount($)
bvE(0/1) * Factor_bvE * Amount($)
bvF(0/1) * Factor_bvF * Amount($)
bvG(0/1) * Factor_bvG * Amount($)
bvH(0/1) * Factor_bvH * Amount($)
}
Calc_SubType2 {
(...)
}
(...)
}

TypeB.CalcValues {
(...)

}
The manager of my project doesn't agree with this structure because it
will create a lot of objects and consume lots of memory each time a
user decides to open a client account, and the application is supposed
to allow the user to open as many clients has he wishes. I'm also not
happy with it but a better solution hasn't occurred to me yet. Any
suggestions?

Thank you
Hugo

"Dan Bass" <Not Listed> wrote in message news:<e3**************@TK2MSFTNGP14.phx.gbl>...
Could you explain briefly what you're trying to do, rather than explaining
how you're trying to do it...
From evaluating a problem, we can the provide recommendations, opinions and
ideas as to where you could go.

Thanks

Dan.

"hufel" <hu*********@yahoo.com> wrote in message
news:5c**************************@posting.google.c om...
Hi,
I'm doing my first big project in C# and I'm stuck with a problem that
I believe has a simple and efficient solution for it (I just haven't
bumped into it yet...). The concept is the following:

//Users manage clients. When the system creates the client it must
fetch the information from the DB and allow some modifications:

Client client = new Client("test");
MasterAccount ma = new MasterAccount(1324651);
client.MasterAccount = ma;
PurchaseItems pi = client.MasterAccount.GetPurchasedItems();
FillListview(pi);

// when a user selects a line in the listview, he must have the
possibility to split each line into two or more lines:

pi[0].Subitem[0..n]

// Each Subitem contains in turn two variables that will in turn be
instanced into two new classes:

Subitem si = pi[0].Subitem[0];
si.TypeA = new Type();
si.TypeB = new Type();

//TypeA and TypeB are of the same type. But in turn contain more class
variables inside

si.TypeA.SubType0
si.TypeA.SubType1
si.TypeA.SubType2
si.TypeA.SubType3

//The SubTypes contain only bool variables and a method.

My problem is that this is a representation in a "object oriented way"
(I think) of what the user sees on screen, but in terms of
calculations and memory comsumption it is not efficient, although it
is flexible enough to make future modification easy.

The problem is that now I'm stuck with this concept, and although I'm
trying to model other solutions in UML, I am not getting anywhere in
order to improve this. A friend suggested storing the values in arrays
and looping through it in order to calculate the values but I dislike
the idea due to (in my opinion) complicated implementation and the
fact that the code becomes much more difficult to understand and
modify in the future.

Please correct me if I'm wrong, through ideas in, whatever...
I welcome all suggestions.

PS. I thought about using patterns, like the singleton pattern or the
flyweight pattern, however I haven't seen real live examples and so I
don't understand how I could use them in my application.

Thank in advance
Hugo

Nov 16 '05 #3
Hugo,

So what you are trying to do, is work out how much cost is involved in the
customer purchasing items.
The items consist of sub parts and components with individual prices, and
the customer can choose to have a selection of parts making up this item.
Is this correct?

Starting from the bottom in a data type heirarchy, the most basic element is
the boolean variable saying whether the customer wants an item, and
presumably the price?

The OO way would then be to build a type that contains one boolean and value
pair.

class SubTypeFactor
{
private bool _itemSelected = false;
private float _priceFactor = 0.0;

public bool ItemSelected
{
get
{
return _itemSelected;
}
set
{
_itemSelected = value;
}
}

public float PriceFactor
{
// get and set for _priceFactor here
}
}
From what I can gather, your "subtypes" would then contain ArrayList of
SubTypeFactor objects as well as a costing for that subtype. For any subtype
the value would be made to be something like this...
float totalAmount = 0.0;
foreach ( SubTypeFactor stf in subTypeObject.Factors )
{
totalAmount += stf.PriceFactor *
Convert.ToFloat(stf.ItemSelected)
}
Each SubType object would look like this:
class SubType
{
private float
private ArrayList _factor = new ArrayList;

public void AddFactor ( SubTypeFactor stf )
{
// adds a factor to the factor arrayList
}

void CalculatePricing ()
{
// contains the above code snippet in the previous
paragraph
}

}

From here, each item for sale would contain these sub types, etc etc...

The amount of memory used depends on the amount of data there for the
customer to choose from, not necessarily the structure in which it's stored
(although inefficient structures repeating data etc etc will slow things
down further).

If I've missed the mark let me know and we'll see what we can help you with.

Thanks.

"hufel" <hu*********@yahoo.com> wrote in message
news:5c*************************@posting.google.co m...
I'll do my best to explain:

The application main purpose is to retrieve information regarding
purchased items by a client. Each client has a masteraccount. He uses
this MasterAccount to purchase items. This is were I begin the hard
part. I must read the items, show them in a listview and allow the
user of my application to split each item into two or more subItems.
Each SubItem contains two more pieces of information that I simply
called 'TypeA' and 'TypeB'. When the user starts working the
information regarding 'TypeA', he is filling information regarding the
client divided into 4 'blocks' that I called SubTypes. Each SubType
contains several boolean variables. I need to read the information
contained in these boolean variables, multiply it by a factor directly
related to each variable and by the amount spent on the original item.
The result is calculated at the subItem level. These values are stored
inside a sql server 2000 db.

Pseudocode:

bvA =
Client.MasterAccount.PurchasedItems[].Subitems[].TypeA.SubType0.BoolVarA;
foreach (purchasedItem)
foreach (SubItem)
TypeA.CalcValues {
Calc_SubType0 {
bvA(0/1) * Factor_bvA * Amount($)
bvB(0/1) * Factor_bvB * Amount($)
bvC(0/1) * Factor_bvC * Amount($)
}
Calc_SubType1 {
bvD(0/1) * Factor_bvD * Amount($)
bvE(0/1) * Factor_bvE * Amount($)
bvF(0/1) * Factor_bvF * Amount($)
bvG(0/1) * Factor_bvG * Amount($)
bvH(0/1) * Factor_bvH * Amount($)
}
Calc_SubType2 {
(...)
}
(...)
}

TypeB.CalcValues {
(...)

}
The manager of my project doesn't agree with this structure because it
will create a lot of objects and consume lots of memory each time a
user decides to open a client account, and the application is supposed
to allow the user to open as many clients has he wishes. I'm also not
happy with it but a better solution hasn't occurred to me yet. Any
suggestions?

Thank you
Hugo

"Dan Bass" <Not Listed> wrote in message
news:<e3**************@TK2MSFTNGP14.phx.gbl>...
Could you explain briefly what you're trying to do, rather than
explaining
how you're trying to do it...
From evaluating a problem, we can the provide recommendations, opinions
and
ideas as to where you could go.

Thanks

Dan.

"hufel" <hu*********@yahoo.com> wrote in message
news:5c**************************@posting.google.c om...
> Hi,
> I'm doing my first big project in C# and I'm stuck with a problem that
> I believe has a simple and efficient solution for it (I just haven't
> bumped into it yet...). The concept is the following:
>
> //Users manage clients. When the system creates the client it must
> fetch the information from the DB and allow some modifications:
>
> Client client = new Client("test");
> MasterAccount ma = new MasterAccount(1324651);
> client.MasterAccount = ma;
> PurchaseItems pi = client.MasterAccount.GetPurchasedItems();
> FillListview(pi);
>
> // when a user selects a line in the listview, he must have the
> possibility to split each line into two or more lines:
>
> pi[0].Subitem[0..n]
>
> // Each Subitem contains in turn two variables that will in turn be
> instanced into two new classes:
>
> Subitem si = pi[0].Subitem[0];
> si.TypeA = new Type();
> si.TypeB = new Type();
>
> //TypeA and TypeB are of the same type. But in turn contain more class
> variables inside
>
> si.TypeA.SubType0
> si.TypeA.SubType1
> si.TypeA.SubType2
> si.TypeA.SubType3
>
> //The SubTypes contain only bool variables and a method.
>
> My problem is that this is a representation in a "object oriented way"
> (I think) of what the user sees on screen, but in terms of
> calculations and memory comsumption it is not efficient, although it
> is flexible enough to make future modification easy.
>
> The problem is that now I'm stuck with this concept, and although I'm
> trying to model other solutions in UML, I am not getting anywhere in
> order to improve this. A friend suggested storing the values in arrays
> and looping through it in order to calculate the values but I dislike
> the idea due to (in my opinion) complicated implementation and the
> fact that the code becomes much more difficult to understand and
> modify in the future.
>
> Please correct me if I'm wrong, through ideas in, whatever...
> I welcome all suggestions.
>
> PS. I thought about using patterns, like the singleton pattern or the
> flyweight pattern, however I haven't seen real live examples and so I
> don't understand how I could use them in my application.
>
> Thank in advance
> Hugo

Nov 16 '05 #4
Thanks Dan, I used a portion of your code and I'm building another
structure that seems much more efective to me.

Thanks a lot
Hugo
Dan Bass wrote:
Hugo,

So what you are trying to do, is work out how much cost is involved in the customer purchasing items.
The items consist of sub parts and components with individual prices, and the customer can choose to have a selection of parts making up this item. Is this correct?

Starting from the bottom in a data type heirarchy, the most basic element is the boolean variable saying whether the customer wants an item, and
presumably the price?

The OO way would then be to build a type that contains one boolean and value pair.

class SubTypeFactor
{
private bool _itemSelected = false;
private float _priceFactor = 0.0;

public bool ItemSelected
{
get
{
return _itemSelected;
}
set
{
_itemSelected = value;
}
}

public float PriceFactor
{
// get and set for _priceFactor here
}
}
From what I can gather, your "subtypes" would then contain ArrayList of SubTypeFactor objects as well as a costing for that subtype. For any subtype the value would be made to be something like this...
float totalAmount = 0.0;
foreach ( SubTypeFactor stf in subTypeObject.Factors )
{
totalAmount += stf.PriceFactor *
Convert.ToFloat(stf.ItemSelected)
}
Each SubType object would look like this:
class SubType
{
private float
private ArrayList _factor = new ArrayList;

public void AddFactor ( SubTypeFactor stf )
{
// adds a factor to the factor arrayList
}

void CalculatePricing ()
{
// contains the above code snippet in the previous
paragraph
}

}

From here, each item for sale would contain these sub types, etc etc...
The amount of memory used depends on the amount of data there for the customer to choose from, not necessarily the structure in which it's stored (although inefficient structures repeating data etc etc will slow things down further).

If I've missed the mark let me know and we'll see what we can help you with.
Thanks.


Nov 16 '05 #5

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

Similar topics

7
by: Dave Townsend | last post by:
Hi, I came across a little problem the other day, I wonder if anyone has a more elegant solution: I have a class which has some "pixmap" members, this is a QT-data type which is similar to a...
4
by: Rui.Hu719 | last post by:
Hi, All: I read the following passage from a book: "There are three exceptions to the rule that headers should not contain definitions: classes, const objects whose value is known at compile...
12
by: elty123 | last post by:
I have a small C# program (about 400 lines of code) that is only 28kb after compiled. However when it runs (takes a whole 5 seconds) it takes up nearly 20MB of memory and I don't see why. ...
2
by: Steven D'Aprano | last post by:
I understood that HTTPError objects always have a read method, so they can be treated as if they were a webpage. E.g. something like this simplified snippet: address =...
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,...
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.