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

Having trouble achiving OOP zen

Hi all,

Disclaimer: This app is actually written in a different language, but I have
much respect for this group & wanted to get your input so please ignore any
minor syntactical errors.

I have a program that needs to perform an action: Inventory Adjustment.
This action takes several arguments:

Data to describe which item to adjust:
- Site
- Item
- Lot
- Serial #

The adjustment(s) to make:
- Quantity
- Expire Date

Goals: I have two user interfaces (Telnet/VT100 & Windows GUI), so I want to
use one set of validation code for both of them. Furthermore I don't want
any GUI code to be directly dependant on the DataAccess objects & methods.

So I was thinking this:

Class InventoryAdjustment
{
Private:
string site_id, item_id, lot, serial_no;

Public:
void setSite( site );
void setItem( item );
void setLot( lot );
void setSerial( serial );
void Adjust( qty, expire_dt );
};

So the validation functions look up the parameter, and throw an error if it
is not valid data, or save it for the Adjustment if it is valid: setSite(
site_id ) calls the data access object, which has a method bool
SiteIsValid(site_id), which in-turn runs the queries against our data.

Then, when Adjust( ) is called, it uses the stored data & the 2 input params
to perform the adjustment. I realize this approach is flawed, and that
perhaps something like this would be better:

Class Inventory
{
Public:
bool Adjust( site_id, item_id, lot, serial_no, qty, expire_dt );
// other actions to perform against inventory
}

But this doesn't provide any validation for the UI's. I guess I just need
some input, because I am starting to loose my mind. Am thinking too hard
about this?

TIA,
Jeremy

Jul 22 '05 #1
6 1272
On Fri, 19 Dec 2003 19:18:20 GMT, "Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote:
Disclaimer: This app is actually written in a different language, but I have
much respect for this group & wanted to get your input so please ignore any
minor syntactical errors.
There is nothing concerning C++ in your question.

So it is off-topic in [comp.lang.c++].

I suggest [comp.programming], to which this reply is crossposted, and
follow-ups redirected.

I have a program that needs to perform an action: Inventory Adjustment.
This action takes several arguments:

Data to describe which item to adjust:
- Site
- Item
- Lot
- Serial #
Is _all_ of this required to identify the item?

What is 'Item'?

Anyways, to start with the above yields a class ItemId.
The adjustment(s) to make:
- Quantity
- Expire Date
These are presumably attributes of Item.
Goals: I have two user interfaces (Telnet/VT100 & Windows GUI), so I want to
use one set of validation code for both of them. Furthermore I don't want
any GUI code to be directly dependant on the DataAccess objects & methods.

So I was thinking this:

Class InventoryAdjustment
{
Private:
string site_id, item_id, lot, serial_no;

Public:
void setSite( site );
void setItem( item );
void setLot( lot );
void setSerial( serial );
void Adjust( qty, expire_dt );
};
Good brainstorming.

I suggest (1) removing the Adjust-method, in effect, the knowledge of Item
innards, (2) removing the first four methods, replace by a member of type
ItemId, which should be initialized by and only by constructor(s), (3) add
getters and setters or possibly just public members for qty and expire_dt.

Hm, with that it's something else: not a "doer" class, but a class where
each instance _specifies_ an adjustment to be made.
So the validation functions look up the parameter, and throw an error if it
is not valid data, or save it for the Adjustment if it is valid: setSite(
site_id ) calls the data access object, which has a method bool
SiteIsValid(site_id), which in-turn runs the queries against our data.

Then, when Adjust( ) is called, it uses the stored data & the 2 input params
to perform the adjustment. I realize this approach is flawed, and that
perhaps something like this would be better:
Not better: needed _in addition_.
Class Inventory
{
Public:
bool Adjust( site_id, item_id, lot, serial_no, qty, expire_dt );
// other actions to perform against inventory
}

But this doesn't provide any validation for the UI's.


Oh yes it does, it's the final server-side validation.

Earlier on you will have validated that the InventoryAdjustment
instance (which should replace the current arguments of Adjust) is
valid as far as the client side is able to determine.

It's a two-step process: validate as much as possible on the client
side, then final validation in the outermost level of server-side.
XFUT: [comp.programming]

Jul 22 '05 #2
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote...
Disclaimer: This app is actually written in a different language, but I have much respect for this group & wanted to get your input so please ignore any minor syntactical errors.
[...]


2 recommendations:
"Advanced C++: Programming Styles and Idioms" by James Coplien
news:comp.object

Victor
Jul 22 '05 #3
Jeremy Cowles wrote:
Hi all,

Disclaimer: This app is actually written in a different language, but I have
much respect for this group & wanted to get your input so please ignore any
minor syntactical errors.

I have a program that needs to perform an action: Inventory Adjustment.
This action takes several arguments:

Data to describe which item to adjust:
- Site
- Item
- Lot
- Serial #

The adjustment(s) to make:
- Quantity
- Expire Date

Goals: I have two user interfaces (Telnet/VT100 & Windows GUI), so I want to
use one set of validation code for both of them. Furthermore I don't want
any GUI code to be directly dependant on the DataAccess objects & methods.
Are you trying to implement a strict Model/View/Controller architecture?

So I was thinking this:

Class InventoryAdjustment
{
Private:
string site_id, item_id, lot, serial_no;

Public:
void setSite( site );
void setItem( item );
void setLot( lot );
void setSerial( serial );
void Adjust( qty, expire_dt );
};

So the validation functions look up the parameter, and throw an error if it
is not valid data, or save it for the Adjustment if it is valid: setSite(
site_id ) calls the data access object, which has a method bool
SiteIsValid(site_id), which in-turn runs the queries against our data.

Then, when Adjust( ) is called, it uses the stored data & the 2 input params
to perform the adjustment. I realize this approach is flawed, and that
perhaps something like this would be better:

Class Inventory
{
Public:
bool Adjust( site_id, item_id, lot, serial_no, qty, expire_dt );
// other actions to perform against inventory
}

But this doesn't provide any validation for the UI's. I guess I just need
some input, because I am starting to loose my mind. Am thinking too hard
about this?

TIA,
Jeremy


How about this:

struct InventoryController
{
void Adjust( Site, Item, Lot, SerialNo, ExpirationDate );
}

-Jeff

Jul 22 '05 #4
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote in message
news:0a**********************@twister.tampabay.rr. com...
Hi all,

Disclaimer: This app is actually written in a different language, but I have much respect for this group & wanted to get your input so please ignore any minor syntactical errors.

I have a program that needs to perform an action: Inventory Adjustment.
This action takes several arguments:

Data to describe which item to adjust:
- Site
- Item
- Lot
- Serial #

The adjustment(s) to make:
- Quantity
- Expire Date

Goals: I have two user interfaces (Telnet/VT100 & Windows GUI), so I want to use one set of validation code for both of them. Furthermore I don't want
any GUI code to be directly dependant on the DataAccess objects & methods.

So I was thinking this:

Class InventoryAdjustment
{
Private:
string site_id, item_id, lot, serial_no;

Public:
void setSite( site );
void setItem( item );
void setLot( lot );
void setSerial( serial );
void Adjust( qty, expire_dt );
};

So the validation functions look up the parameter, and throw an error if it is not valid data, or save it for the Adjustment if it is valid: setSite(
site_id ) calls the data access object, which has a method bool
SiteIsValid(site_id), which in-turn runs the queries against our data.

Then, when Adjust( ) is called, it uses the stored data & the 2 input params to perform the adjustment. I realize this approach is flawed, and that
perhaps something like this would be better:

Class Inventory
{
Public:
bool Adjust( site_id, item_id, lot, serial_no, qty, expire_dt );
// other actions to perform against inventory
}

But this doesn't provide any validation for the UI's. I guess I just need
some input, because I am starting to loose my mind. Am thinking too hard
about this?

TIA,
Jeremy


I don't quite follow exactly what your requirements are, but generally
speaking I have found it useful to write an "abstract UI" which does all the
logical operations (e.g. input validation) but knows nothing about buttons
and things, and a "concrete UI" which knows about buttons and things but
knows as little as possible about the logic. In your case I think you would
write two concrete UI's, one for Telnet and one for Windows GUI. If you do
it right you won't have much trouble adding a third for a web interface,
etc.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #5
In article <0a**********************@twister.tampabay.rr.com> ,
jeremy.cowles[nosp@m]asifl.com says...

[ ... ]
I have a program that needs to perform an action: Inventory Adjustment.
This action takes several arguments:
IMO, it should take two arguments.
Data to describe which item to adjust:
- Site
- Item
- Lot
- Serial #
IMO, these should be combined into an item_identifier or something on
that order.
The adjustment(s) to make:
- Quantity
- Expire Date
and these should be combined into an item_data or something on that
order.

[ ... ]
Public:
void setSite( site );
void setItem( item );
void setLot( lot );
void setSerial( serial );
void Adjust( qty, expire_dt );


IMO, this is a rather poor design -- at least as I read things, it means
that adjusting one item requires that you call 5 functions in a row.
Furthermore, calling Adjust() when you haven't just called the other
four functions is probably an error. IOW, you're creating a modal
interface, which is something you _generally_ want to avoid if you can.

In this case it's easy to avoid: you have:

int adjust(item_identifier const &item, item_data const &data) {

real_item *r;

if ( !verify(item))
return BAD_ID;

if ( NULL == (r=lookup(item)))
return NO_ITEM;

if ( ! real_item->set_value(data))
return BAD_VALS;
}

Note that doing this in a single operation does NOT prevent you from
checking all the parameters. For the moment, I've used a single,
generic BAD_ID to identify all bad IDs, but in reality, you can have
verify return a value indicating what was bad in the ID, and pass that
through to the outside world. Likewise with the values -- if a value is
out of bounds (for example) your return could indicate which one and
what was bad about the value.

Keep in mind that all the OOP stuff is, in the end, supposed to make
your programs simpler, largely by making an object more independent and
intelligent. An object that takes five function calls to accomplish one
simple action defeats the purpose.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #6
So I should: stop posting in the wrong group, read a book about OOP models
in C++, remove my validation code from he actual logic, and make a layer
between the physical UI and the logic.

Thanks, everyone, for your replies.
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote in message
news:0a**********************@twister.tampabay.rr. com...
Hi all,

Disclaimer: This app is actually written in a different language, but I have much respect for this group & wanted to get your input so please ignore any minor syntactical errors.

I have a program that needs to perform an action: Inventory Adjustment.
This action takes several arguments:

Data to describe which item to adjust:
- Site
- Item
- Lot
- Serial #

The adjustment(s) to make:
- Quantity
- Expire Date

Goals: I have two user interfaces (Telnet/VT100 & Windows GUI), so I want to use one set of validation code for both of them. Furthermore I don't want
any GUI code to be directly dependant on the DataAccess objects & methods.

So I was thinking this:

Class InventoryAdjustment
{
Private:
string site_id, item_id, lot, serial_no;

Public:
void setSite( site );
void setItem( item );
void setLot( lot );
void setSerial( serial );
void Adjust( qty, expire_dt );
};

So the validation functions look up the parameter, and throw an error if it is not valid data, or save it for the Adjustment if it is valid: setSite(
site_id ) calls the data access object, which has a method bool
SiteIsValid(site_id), which in-turn runs the queries against our data.

Then, when Adjust( ) is called, it uses the stored data & the 2 input params to perform the adjustment. I realize this approach is flawed, and that
perhaps something like this would be better:

Class Inventory
{
Public:
bool Adjust( site_id, item_id, lot, serial_no, qty, expire_dt );
// other actions to perform against inventory
}

But this doesn't provide any validation for the UI's. I guess I just need
some input, because I am starting to loose my mind. Am thinking too hard
about this?

TIA,
Jeremy


Jul 22 '05 #7

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

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
1
by: ajackson | last post by:
i am having some trouble installing SQl server Reporting Services. well, in order to install the reporting services i have to install Service Pack 3a. so through my installation of package 3a i...
1
by: mr_burns | last post by:
hi there, Ive been having a few problems recently with this group. Im not sure if any of the other groups have been giving me trouble but recently this one has a couple of times, when attempting...
2
by: ed | last post by:
i'm having trouble with a form. I want to be able to type in the address of the form with the data for the form items in the URL (ie: http://somesite.com/formpage.html?field1=data1&field2=data2)....
1
by: Lauren Wilson | last post by:
I'm having trouble with the Access VBA help on my installation of A2K with Dev tools. Every time I try to retrieve help for items listed in the Object Browser (and SOME other items as well),...
2
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk =...
0
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server...
1
by: Jozef | last post by:
Hello. I'm having trouble creating a blank solution (and ASP.net web application) from my laptop. I own the server (in fact it's sitting right next to me) and have added the URL to the trusted...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...
0
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,...

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.