• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Service, Relationships and Classes

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, what i'm trying to do here is an Ordering system for a restaurant. What I can't seem to figure out is to add a product to an order in the Service with the input parameters being the tableNR. the product that should be ordered and the amount. Been trying to getting this to work all day but cant seem to figure it out.

Code
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the code you are having problems with here in the thread. Be sure to wrap the code in code tags to preserve its formatting.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,thanks for that.

How do you execute the program for testing? I do not see a main() method.
 
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kees deVries, welcome to the Ranch.

Please explain what is the logical difference between Order and OrderProduct? In the simple life example.

Also, please explain what this line does in OrderProduct class constructor:

Don't know current how to do, but it doesn't sound complicated task.

Almost all variable names you chose, you chose poor ones. Would suggest to re-think those.
 
Liutauras Vilda
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those lines (2 and 3)Change to:

This method says it should show all products, but to my surprise it returns a list of products, it is not what the method name suggests. Same problems with showAllOrderedProducts, showAllTables, and probably more. Spend more time on choosing not misleading method names.
 
Liutauras Vilda
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not entirely sure it is Product's responsibility to know how many of themselves are left. Refering to the part:
Let's see what others think on that.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some explanation:

its a web application with JSP , servlets and DAO's I don't have a main no, since, at first, I was only working with the database and DAO's. so, i would put it all in the RestaurantService.

OrderProduct is one many bad naming choices i chose it seems. it could better be names OrderLine.
The order holds multiple orderLines and each orderLine has one product. I'm trying to figure out how to make that happen in the service. And yes, I am keeping orders in a list, which will be saved to the database once the order has been paid
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If possible, it might be useful to have a main() for testing.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:I am not entirely sure it is Product's responsibility to know how many of themselves are left. . . .

Agree. The product should know its description, number, price, etc., but there should be a stock class which can list how many products there are.

As an alternative have a StockLine<T> class which simply stores a product and number in stock. The stock object might have a List<StockLine> to store all the products, but a Map will give better functionality.

And welcome to the Ranch
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, if I understand this correctly, it should be something like: Order has a list of orderLines. orderline has has 1 product, product has stockline,and stockline has stock/warehouse.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:So, if I understand this correctly, it should be something like: Order has a list of orderLines. orderline has has 1 product,


Sounds about right to me.

product has stockline,and stockline has stock/warehouse.


That sounds more like an inventory system to me, not stock control for a restaurant. Where does a warehouse come into it?

I think you need to be absolutely clear what a "product" is here. Is it a meal (or dessert, or drink) - ie, the stuff you sell - or is it the ingredients you use (and buy) to make a meal?

A restaurant (or the chef in it) is basically in the business of converting one to the other, and hopefully making a profit in the process.

One possible distinction is:
1. A Product - something you buy - eg, Bacon, Beans, Beef, Celery....
2. A MenuItem - something you sell (and presumably on a Menu) - eg, English Breakfast, Weinerschnitzel, Creme Caramel, Cafe au lait...

Either way, I wouldn't tie stock information to a Product (except possibly something like a "list" or "normal" price); that's the business of a Stock or Inventory object. A StockLine may well have a Product, but not the other way around.

And how you tie the products you buy to the ingredients you use is another interesting problem. I suspect you might want some sort of Portion class; but TBH, I've never thought it through in any great detail.

HIH

Winston
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im trying to keep it as simple as possible. I have No table class, No customer class, No bill. So the only thing i Will have to add is a Stock line. Or Stock? The main confusing part for me is that when you create a new order object, it only has a orderID and tableNR. And order line has amount ... wait Let me explain More clear. How do i get the product into the order? Since it has to to from product all the way to order.
 
Liutauras Vilda
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:Im trying to keep it as simple as possible. I have No table class, No customer class, No bill. So the only thing i Will have to add is a Stock line. Or Stock? The main confusing part for me is that when you create a new order object, it only has a orderID and tableNR. And order line has amount ... wait Let me explain More clear. How do i get the product into the order? Since it has to to from product all the way to order.

Have you tried to draw an UML class diagram? That would help for yourself to see the structure of classes and their relations. You could draw one and share it.

How do i get the product into the order?

That suggests that Order HAS-A product/-s, for which is needed some kind of data structure to hold more than one of those and a method to add a product at any time in case customer wants a dessert after the main meal.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I have http://puu.sh/pu7Mo/04e7f780f3.png
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:Im trying to keep it as simple as possible. I have No table class, No customer class, No bill.
So the only thing i Will have to add is a Stock line. Or Stock?


Why? You haven't yet explained what a "Product" IS; and if it's on an Order (which sound suspiciously like an order to the kitchen to me), then "stock" doesn't come into it - unless you want it to. A customer Order will consist of a list of items from a menu - hence my MenuItem suggestion above (although you may call it a "Product").

The main confusing part for me is that when you create a new order object, it only has a orderID and tableNR.


Those are presumably required for a database - hence the 'DAO' in your class names - they are not required by Java, since any object can be accessed by its reference.

And order line has amount ... wait Let me explain More clear. How do i get the product into the order? Since it has to to from product all the way to order.


I'm not quite sure what "amount" you're referring to. If I order 2 "Cafe au laits", then presumably the amount is 2. The "Cafe au lait", on the other hand, is likely to be an item is a Menu, which should also include the price.

So, what I suspect you want is something like this:
Product - Something you sell, or a customer orders, with a price.
Menu - A list (or Map) of ALL Products sold by the restaurant.
Order - A list of Products ordered by a customer.
OrderLine - A single Product in an Order, including a quantity (amount?) and line item total (quantity * price).

Order may also need to include details of tax or discounts, but I leave that up to you.

HIH

Winston
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not getting the Menu part, cannot I just keep a list like in the diagram ?
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:I'm not getting the Menu part, cannot I just keep a list like in the diagram ?


Sure you can, but where? I suppose you could store it in your RestaurantService class (which I suspect should simply be Restaurant), but that's equating a restaurant with its menu, which sounds overly "coupled" to me.

Also: it isn't a List (at least in Java terms), it's a Set.

And you really don't want to be linking objects by "ID"s because those are database fields. OrderProduct should look like this:
HIH

Winston
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, yes i'm having some problems keeping database and Java apart.
So, in this case, what is the difference between the menu class and the product class, and where does menu fit within the diagram?
(I reckon the menu class isn't in the database either?)
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:So, in this case, what is the difference between the menu class and the product class, and where does menu fit within the diagram?
(I reckon the menu class isn't in the database either?)


Right, well first, I assume that a "Product" is something (an individual thing) that the restaurant sells - like Steak & Chips, or a cup of tea.

What happens when you go into a restaurant? You usually get given a menu, which is list (or, as I say, a Set, because you don't want duplicates) of things (Products) that the restaurant offers. So:

Product - A single item - eg, Coq au Vin.
Menu - The set of Products on offer at the restaurant.

so the relationship between is Menu and Product is:
  Menu−−−1:M−−>Product.

The fact is that in your case there's probably a 1:1 relationship between your RestaurantService class and your Menu, but that doesn't mean they're the same thing. It's probably more like "Restaurant has-a Menu",

HIH

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:Alright, yes i'm having some problems keeping database and Java apart.


Which is probably fine if your diagram is an ERD for your database (I suspect UML calls them something different). Just remember that IDs connect tables; references connect objects.

HIH

Winston
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, instead of the restaurantService holding a list of products, the service holds a menu. with a set of products that the restaurant has?
 
Liutauras Vilda
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:So, instead of the restaurantService holding a list of products, the service holds a menu. with a set of products that the restaurant has?

Were you given some description about the whole system where you could find some hints on design, or you were given such diagram (you showed earlier) and need to implement it as it is?
However, it looks a bit too primitive as for a restaurant system.

Here are some insights for you to think of, maybe will find something useful to take as an idea to improve design.

1. Restaurant has Restaurant Services and Products, it knows how many different services it provides and how many products it has.
2. Product contains its price, used by date, maybe even Ingredients?
3. Restaurant Services provides Menu and accepts Orders to deliver to customers.
4. Restaurant Services maybe of different types: Takeaway and EatIn (extends Restaurant Services), which provides different Menu's (interface)?
5. Menu contains Meals which are made of Products and maybe has standalone Products on offer, not necessarily all types Restaurant have in stock.
6. Order contains Meals/Products, table number, price.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:So, instead of the restaurantService holding a list of products, the service holds a menu. with a set of products that the restaurant has?


That would be my interpretation; but it's by no means the only one. Liutauras has given you an even more comprehensive model but, as he says, without knowing what you've been asked to do, or precisely what your database looks like (I presume the idea is to save all this information on one), it's difficult to give specific advice.

All I can say is:
1. Stick as closely as you can to the instructions you've been given - ie, don't worry about modelling information you haven't been asked to.

For example: You've decided not to included a "table" entity, which may be just fine for your purposes; but in a real restaurant system, Table might well be a proper object, with an associated number (your tableNR), the number of people it seats, and perhaps a shape (circular, oval, square) and dimensions for fitting into seating plans.

2. Within the constraints of (1), don't AVOID creating classes (or entities) simply to save time or "keep things simple". Unfortunately, in modelling, making thing too simple often leads to the exact opposite.

HIH

Winston
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thing is, i Made this up my self. And school approved it. But during my visits at school they stripped a lot like the table and bill classes cause that would Make it to difficult as a beginner. Trying to make it as simple as possible
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:Thing is, i Made this up my self. And school approved it. But during my visits at school they stripped a lot like the table and bill classes cause that would Make it to difficult as a beginner. Trying to make it as simple as possible


In which case, my advice is to write out, point-by-point, exactly what you want your RestaurantService to do ...
in English; not in Java-ese. And do it before you write another line of code.

Imagine you're writing those instructions for someone else. What would you need to tell them to write such a class (or classes)? What would tell you if they got it wrong, or did too much?

Right now, it's very difficult to give any more concrete suggestions because we simply don't know what you're trying to do, or what advice you've already been given..

Winston
 
Ranch Hand
Posts: 235
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The more comments I read, it became more and more apparent this was a school assignment. Now that that is covered let's get to the fun stuff -- writing code.

Oh wait, we aren't sure exactly what it we need to code. Time to turn Mr. Computer off, and find our other friends --Paper and Pencil. After some thought, I realise I am creating an ordering system for a restaurant. After a little more thought, and some serious doodling, I realised that I don't know what an order. In column one, we have an order that is that pesky thing those bothersome customers give to the waitress/waiter/PC term goes here. That order is then given to the chef, who then does what ever it is that chefs do. But in column two, an order could be what the ordering person creates and then informs someone in a far-away place and ask then to bring you all things on that list to the restaurant.

Need to figure out what an order is. It could be one of many things. Can't code, can't create a database and tables and what not until that decision gets made. Where did I put that quarter?

All kidding and joking aside, YOU need to decide what an order does. While I agree with Winston's comments on following the course objectives, you are the only one that can decide or determine which classes you will need. Given the information we have, I don't see a need for a table or bill class. But YOU might/

Regards,
Robert
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, So, what I want the RestaurantService(And most of the application) to do Is the following:
1. Show/return (could someone elaborate on the two) a list of all available products that the restaurant sells.
2. Add product to an order of the selected table(tableNR): All tables have orders, even when there's no one sitting at the table. Once the table wants to pay Paid gets set to 1 and in the database, the table gets assigned a new orderID. (I don't know how this is gonna work in java since you just all told me ID is not java like e.g. you pass objects not ID's)
3.Show/return entire order of the selected table incl price etc. (bill sorta)
4. pay. Never thought of this before bu I may need it in the service.
5. Holding a list of orders.

That sums it up for the Service then,:
Order:
As previously mentioned, service holds a list of this.
Methods,
1. Calculate the price of all the products in the order.
2. Pay? I seriously don't know whether i should put this here or in the service.
3. hold a list with OrderLines
OrderLine:
1 product with an amount gets put in here.
1. Calculate the price with the given the amount.
Product:
the item the restaurant sells

 
Liutauras Vilda
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:All tables have orders, even when there's no one sitting at the table.

One remark. I'd think other way round. Restaurant Services have/receive orders, which have table numbers written on them. Tables don't provide services, so they cannot have orders - they can know what they have ordered though.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Kees deVries wrote:All tables have orders, even when there's no one sitting at the table.

One remark. I'd think other way round. Restaurant Services have/receive orders, which have table numbers written on them. Tables don't provide services, so they cannot have orders - they can know what they have ordered though.



Saying like, I would like to order 5 beers, for table 6. And the Service gets that and adds it to the order, if there is one.
 
Liutauras Vilda
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I gave a thought again. Tables belongs to restaurant. Maybe makes sense that tables has orders, bill. Draw diagrams for yourself, try various ways, so you could see the possible flaws in one or other design decision.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Been there, done that. scrapped Bills and tables in both the class and database diagram
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kees deVries wrote:Alright, So, what I want the RestaurantService(And most of the application) to do Is the following:


OK, well in information terms, I'd say that means you have 4 basic entities: Restaurant (or RestaurantService), Order, Product and Table - with Order probably needing to be broken down in more detail (eg, your OrderProduct class; although there are other alternatives).
Restaurant is your "root" entity since, without it, there would be no reason to write this program; so the likelihood is that all relationships will "radiate" out from it, either directly or indirectly.

Don't worry for the moment about the fact that you're not going to store a table of Tables - that's implementation - but an Order will be useless if you don't know which Table it belongs to; and that, in information terms, makes it an entity that has to be uniquely identified.
And for that reason alone, it might be worth considering making it a Java class, even if right now it only has one field (tableNr; or, even better, Table.number).

Personally, I'd also add a Menu class, simply to hold all the Products that your Restaurant serves (in the same way that many restaurants do); but based on your requirements, it's not strictly necessary. My reasoning is that "menu design" (ie, the Products to add or exclude) is quite an important aspect of a chef's duties, and putting it in a separate class allows for that "side" of the business to be developed separately from what you're doing; but if you decide to leave it out, I can understand.

Going back to Order - one thing I notice is that you don't have a "customer" or "person". Now again, there's nothing explicit in your requirements that suggests that you need one, but many restaurants - especially in North America - design their bills so that large tables can pay for their meals separately.

However, maybe that's for "version 2"...

Winston
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well then i will revise my diagram, to make sure table is in there. Table.number? never heard of that kind of notation. I still don't really understand menu, since i have the product class, with the original idea of letting the service keep a list of the products in the database: the products that the restaurant sells.

And yes I don't have customer. Here(Europe) It's usually the case, with adults, that only one person pays. Otherwise you're giving the restaurant more work with the cashing machine to make sure the full bill is paid. Anyway, that's why i didn't keep customer.

Again, trying to keep it small. It's not just the java part I need to complete, but also the database with DAOs and the JSP front-end.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://puu.sh/pHDuL/452a5ce0e6.png

So, I've added table to the diagram. (again)
Is this how it should be done?
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic