473,225 Members | 1,619 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,225 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 1266
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.