473,834 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object Design Question

Here's what I want to do... sorry for the lengthy description ;-)

I have an inventory tracking system with items that I track stock levels on.
Some items are counted with decimal precision (double) and others are counted
using integers; the database record has a flag that says what kind of item a
particular record is (double or integer). I've created an abstract class
called ItemBase and I implement a concrete class (Item) that inherits from
ItemBase. ItemBase has abstract methods that allow me to get/set the quantity
in stock, or manage collections of items; those methods are implemented in
the concrete class Item. The Item class would be a central part of the
inventory tracking system and I don't want programmers to constantly write
code to check the precision of the number being passed into the methods, I
want to make the counting methods type safe based on the flag in the item's
database record.

Here's an example. When an Item ID is entered into some UI, I want the
client code to be able instantiate an Item object via an Item Factory that
reads the record, figures out what kind of item to build (integer or double)
and hand it back to the client without the client knowing or caring whether
it gets back an integer version or a double version of the Item class. Sounds
easy enough if you're thinking of using generics, but generics requires you
know the type you want when you declare the client instance. Likewise with a
decorator pattern, you have to know in advance what type to create ('cause
even if you decorate a standard Item class with an integer decorator class,
you still have to create your object as the integer decorator in order to
make it's methods visible). I also investigated using Reflection.Emit , but
that doesn't seem like the proper solution either (particularly since it
would make coding more difficult in the long run and clients couldn't code
against an API).

What I want is a completely ignorant client, who gets a type safe Item
object, with integer methods or with double methods, based on what the Item
Factory discovers from the database about the item passed in during object
creation. Anyone have any ideas?

Thanks!
Don
do**********@gm ail.com
May 3 '06
13 1306
>From the original post:
ItemBase has abstract methods that allow me to get/set the quantity
in stock, or manage collections of items; those methods are implemented in
the concrete class Item.


The get/set quantity portion implies he wants to modify the value. To
do that in a typesafe way, he cannot hide the value, as the programmer
using the object will need to know what type of value the item uses in
order to use it properly. Hiding it in a string, or even as an object,
is not typesafe.

However, it occurs to me that it's possible to build this system such
that even though the type of quantity for a particular item is not
known at compile time, it is still obtainable during runtime. That
would allow a programmer to use either an integer value or a float
value depending on the situation.

The simplest way would be to have a base class ItemBase that implements
two get/setters -- ValueInt and ValueFloat, and an ItemType property
that indicated whether the Item is an Int or a Float through an enum.
The concrete classes, ItemInt and ItemFloat, would implement one
getter/setter and throw on the other getter/setter. The programmer
could then simply check the ItemType before using the value, and use an
integer or float type as appropriate.

Wow, that pretty much mirrors the original database.

May 4 '06 #11
On Wed, 3 May 2006 04:58:02 -0700, Don Miller <Don
Mi****@discussi ons.microsoft.c om> wrote:
Here's what I want to do... sorry for the lengthy description ;-)
The quantity can be an int or a double but that value is means nothing
without a unit of measure. Rules based upon UOM can be used to
determine the validity of a quantity. A single item can have multiple
UOMs if the UOM is included as part of a key. The inventory for an
item could be reported as two pallets, three cases and 17 individual
units. With the UOMs known calculating the total number of individual
units won't be complicated. The physical conversion from pallet to
cases or case to items can easily be reflected in the database as
well.

regards
A.G.
I have an inventory tracking system with items that I track stock levels on.
Some items are counted with decimal precision (double) and others are counted
using integers; the database record has a flag that says what kind of item a
particular record is (double or integer). I've created an abstract class
called ItemBase and I implement a concrete class (Item) that inherits from
ItemBase. ItemBase has abstract methods that allow me to get/set the quantity
in stock, or manage collections of items; those methods are implemented in
the concrete class Item. The Item class would be a central part of the
inventory tracking system and I don't want programmers to constantly write
code to check the precision of the number being passed into the methods, I
want to make the counting methods type safe based on the flag in the item's
database record.

Here's an example. When an Item ID is entered into some UI, I want the
client code to be able instantiate an Item object via an Item Factory that
reads the record, figures out what kind of item to build (integer or double)
and hand it back to the client without the client knowing or caring whether
it gets back an integer version or a double version of the Item class. Sounds
easy enough if you're thinking of using generics, but generics requires you
know the type you want when you declare the client instance. Likewise with a
decorator pattern, you have to know in advance what type to create ('cause
even if you decorate a standard Item class with an integer decorator class,
you still have to create your object as the integer decorator in order to
make it's methods visible). I also investigated using Reflection.Emit , but
that doesn't seem like the proper solution either (particularly since it
would make coding more difficult in the long run and clients couldn't code
against an API).

What I want is a completely ignorant client, who gets a type safe Item
object, with integer methods or with double methods, based on what the Item
Factory discovers from the database about the item passed in during object
creation. Anyone have any ideas?

Thanks!
Don
do**********@g mail.com

--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
May 4 '06 #12
Excellent point. I do have uom conversions in the design but hadn't thought
of using them in that way (i.e. for determining inventory quantity). After
much consideration, I think what I'm going to do is declare the quantity as
double throughout the app, then when it's determined the item should use
integers rather than doubles, I'll set some internal precision validator and
have the numbers validated against that (should have thought of that LAST
week!).

Thanks all for your comments--I hope I can return the favor some day...

"Registered User" wrote:
On Wed, 3 May 2006 04:58:02 -0700, Don Miller <Don
Mi****@discussi ons.microsoft.c om> wrote:
Here's what I want to do... sorry for the lengthy description ;-)

The quantity can be an int or a double but that value is means nothing
without a unit of measure. Rules based upon UOM can be used to
determine the validity of a quantity. A single item can have multiple
UOMs if the UOM is included as part of a key. The inventory for an
item could be reported as two pallets, three cases and 17 individual
units. With the UOMs known calculating the total number of individual
units won't be complicated. The physical conversion from pallet to
cases or case to items can easily be reflected in the database as
well.

regards
A.G.
I have an inventory tracking system with items that I track stock levels on.
Some items are counted with decimal precision (double) and others are counted
using integers; the database record has a flag that says what kind of item a
particular record is (double or integer). I've created an abstract class
called ItemBase and I implement a concrete class (Item) that inherits from
ItemBase. ItemBase has abstract methods that allow me to get/set the quantity
in stock, or manage collections of items; those methods are implemented in
the concrete class Item. The Item class would be a central part of the
inventory tracking system and I don't want programmers to constantly write
code to check the precision of the number being passed into the methods, I
want to make the counting methods type safe based on the flag in the item's
database record.

Here's an example. When an Item ID is entered into some UI, I want the
client code to be able instantiate an Item object via an Item Factory that
reads the record, figures out what kind of item to build (integer or double)
and hand it back to the client without the client knowing or caring whether
it gets back an integer version or a double version of the Item class. Sounds
easy enough if you're thinking of using generics, but generics requires you
know the type you want when you declare the client instance. Likewise with a
decorator pattern, you have to know in advance what type to create ('cause
even if you decorate a standard Item class with an integer decorator class,
you still have to create your object as the integer decorator in order to
make it's methods visible). I also investigated using Reflection.Emit , but
that doesn't seem like the proper solution either (particularly since it
would make coding more difficult in the long run and clients couldn't code
against an API).

What I want is a completely ignorant client, who gets a type safe Item
object, with integer methods or with double methods, based on what the Item
Factory discovers from the database about the item passed in during object
creation. Anyone have any ideas?

Thanks!
Don
do**********@g mail.com

--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth

May 5 '06 #13
That's about as close as I'm going to get I'm afraid. In my strugle to solve
the small problem I kinda lost sight of the bigger problem: what type are the
programmers going to set their code to use?!?!?

It's been a very enlightening discussion and thank you both for your input.

"Randolpho" wrote:
From the original post:

ItemBase has abstract methods that allow me to get/set the quantity
in stock, or manage collections of items; those methods are implemented in
the concrete class Item.


The get/set quantity portion implies he wants to modify the value. To
do that in a typesafe way, he cannot hide the value, as the programmer
using the object will need to know what type of value the item uses in
order to use it properly. Hiding it in a string, or even as an object,
is not typesafe.

However, it occurs to me that it's possible to build this system such
that even though the type of quantity for a particular item is not
known at compile time, it is still obtainable during runtime. That
would allow a programmer to use either an integer value or a float
value depending on the situation.

The simplest way would be to have a base class ItemBase that implements
two get/setters -- ValueInt and ValueFloat, and an ItemType property
that indicated whether the Item is an Int or a Float through an enum.
The concrete classes, ItemInt and ItemFloat, would implement one
getter/setter and throw on the other getter/setter. The programmer
could then simply check the ItemType before using the value, and use an
integer or float type as appropriate.

Wow, that pretty much mirrors the original database.

May 5 '06 #14

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

Similar topics

2
3477
by: ggg | last post by:
I'm looking for a complete project/application done with heavy use of of object-oriented programming & design. Preferably something well documented and/or commented so that I can pick it apart and learn how/why they designed it they way they did. Any suggestions?
3
1490
by: andy2O | last post by:
Hello comp.lang.py, Can you help me with ideas for the following (somewhat newbie) OO design question in Python? Note, I'm using psuedo-code, not actual Python for the examples! Background: ----------- I need to represent a small variety of mathematical constructs symbolically using Python classes.
6
4120
by: blueblueblue2005 | last post by:
here is a friend function of Class Array, which has two private data member: int size, int *ptr // Array's public member function to return size int getSize() const { return size; } friend istream &operator>>(istream &in, Array &a) { for(int i=0; i<a.size; i++) // do something
22
2786
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void fun() {
4
1804
by: Carl J. Van Arsdall | last post by:
It seems the more I come to learn about Python as a langauge and the way its used I've come across several discussions where people discuss how to do things using an OO model and then how to design software in a more "Pythonic" way. My question is, should we as python developers be trying to write code that follows more of a python standard or should we try to spend our efforts to stick to a more traditional OO model? For example, in...
17
2600
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do something with b //possibly store in a list
11
1363
by: John A Grandy | last post by:
I'm in a vigorous debate at my work regarding objects assuming knowledge of the type their containing object. This debate pertains specifically to ASP.NET, but I have decided to post in the C# forum because this is where most of the OO gurus hang out, and I view this as a fundamental issue of OO design. In ASP.NET, objects of type WebForm and UserControl have an intrinsic Page property which refers to their containing Page.
0
1165
by: =?Utf-8?B?SmVhbi1GcmFuY29pcyBCcmV0b24=?= | last post by:
"siddharthkhare@hotmail.com" wrote: The context is important in this kind of design concern : I assume there's a lot of user and that application will evolve to add richer functionality. My first concern would be to separate the business logic code from data contener : the new code would look like that : LineItemBusinessComponent.Delete(LineItemBusinessEntity) Exposing CRUD component isn't the best thing to do because your presentation...
3
157
by: H. S. Lahman | last post by:
Responding to siddharthkhare... Ignore Topmind and frebe. They are anti-OO P/R guys. Let's not confuse things with specific 3GL syntax. At the OOA/D level the model looks like: | 1
7
1697
by: joproulx | last post by:
Hi, I was wondering if there was a way with Reflection to find dynamically if an object was referencing indirectly another object. A simple example would be: Object1 | --Object2 |
0
9799
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10512
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9332
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6957
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3981
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3083
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.