× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



James Perkins skrev:
Hi All,
Just looking for a little advice here. I'm trying to (still) wrap my head
around OO design.

I'm working on an application for order entry. I want to take a list of
items and turn them into an order. Not really a big deal, but just the high
level overview.

I have a class Item that looks something like this, mainly the properties is
where my question is.
public class Item {
private boolean active;
private String description;
private int inventoryClass;
private String ean;
private int inventorySubclass;
private String itemNumber;
private String keywords;
private String uom;
private String upc;
private double weight;
...
}
This is most likely a Data Transfer Object you are creating here (http://en.wikipedia.org/wiki/Data_Transfer_Object) so you would build an object only with fields and getters and setters for those.

Unless you have good reason to, do not use double/float/int/ but instead their object equivalents.
Do not use integers to look up in tables for a type, but instead at object creation time use an object which RETURNS the information you need and reference that object in your item. Then you don't hardcode anything inside item, and you have a type safe way of getting from your item to the corresponding inventory/whatever.



I'm wondering now, if inventoryClass should now be a new class
InventoryClass same with inventorySubclass and uom. Make it more generic has
I could make it more generic like so:
public final class InventoryClass<E> {
private final E inventoryClass;

public InventoryClass(E inventoryClass) {
this.inventoryClass = inventoryClass;
}

public final E getInventoryClass() {
return inventoryClass;
}
}

So, my question is this. Am I heading down the right track? Am I thinking to
RPG/procedural programming like?
Generally there is only need for generics if you know you'll be handling multiple objects of (almost) the same type where the actual type is unknown at design time (like lists and so on).

I would suggest that you instead just sub class Item with what you need it to be so you have items but with different behaviour.

If the inventory class is irrelevent to the item as such, consider using interfaces instead so if an item inventory behaves in a specific way, let it implement an according interface providing that behaviour and ask with "instanceof" to see if it is possible.

if (item instanceof Duck) {
Duck duck = (Duck) item;
duck.quack();
}

Any advice is welcome.

Thanks in advance,
--
James R. Perkins

P.S.
If anybody is interested I have created a List factory class that will
return a generic version of a List without having to infer the generics on
the static factory method.
Example:
List<String> list = newArrayList();
If anybody is interested, I'm willing to share. I'm almost done with a Map
one too.
I'd like to see it for sure. I am not quite sure what you are doing, but always willing to learn :)


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.