• 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

Tight Coupling problem

 
Ranch Hand
Posts: 58
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Hopefully this is isn't a beginner level question.

I'm in the early stages of developing a shopping cart application (specific to an individual retail business).

My design includes the following two classes: Product, and ProductGrouping (because the company sells tableware, and the products are grouped into patterns). The ProductGrouping contains a List<Product> (an ArrayList). What I'm finding, however, is that given a particular Product, I want to be able to get a reference to the ProductGrouping (to be able to access information such as the pattern name, manufacturer name etc.). My concern is that giving each Product a reference to its ProductGrouping would lead to tight coupling between the two classes and therefore feels like a bad idea.

Any suggestions would be appreciated.

thanks

Gordy
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add another spanner in the works, can a product belong in more than one product grouping?
 
Gordon Brown
Ranch Hand
Posts: 58
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

good question. it's been decided that it can't, due to the nature of the products the business sells there's no real need for it
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I personally don't see a massive problem with putting in the ProductGroupId on the Product, as you say it can speed those reverse lookups somewhat. Others may disagree with this opinion though, I'm hoping they'll weigh in!
 
Gordon Brown
Ranch Hand
Posts: 58
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response, Martijn. I'm inclined to agree with you, but would be interested if anyone thinks it's a crazy thing to do.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you get a request which says "Show me the information for Product 123" and "the information" would include the product group's description, then that would be a reasonable design. I would rather ask why the product group needs a list of products in that group.
 
Gordon Brown
Ranch Hand
Posts: 58
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah. An example would probably clarify things.

When you display a product, the name "Wedgwood Jasper Conran Blue Butterfly Plate 27cm" is actually made up of information from a number of objects:

Wedgwood is the Manufacturer's name.
Jasper Conran is the Designer's name (won't exist for some patterns)
Blue Butterfly is the ProductGrouping (pattern) name
Plate 27 is obviously the product name.

ProductGrouping has Manufacturer and Designer member variables.

The name of the product itself really isn't enough. For example, in the shopping cart, you want the full name mentioned above.

With regards to the question of why the ProductGrouping has to have a list of products in that group, possibly it doesn't. My initial thought was simply to give each of the Product objects a reference to the ProductGrouping.

But then, logically it just seemed to make sense for the ProductGrouping to have a list of the products within it: It makes it very easy to loop through the products in the view (the most important page on the site will be one that displays all products within a ProductGrouping).



I suppose there's nothing stopping me using a list of products for a given ProductGrouping without making it a member of that ProductGrouping.

Given the concerns above, would you say that approach makes more sense?

btw, I very much appreciate the feedback as I'm a lone developer on this project.

cheers

Gordy

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I expected, that there would be a page which displayed all the products in a grouping. You could implement that by going through all the products and only displaying those which were in a specific grouping, but if there were 15,000 products and you wanted to display a grouping with only 15 products, you could decide that was a waste of resources. But it might not be in real life, it might make the response time for the page be 1.2 seconds with the pre-built list of products and 1.7 seconds without it.

The point I'm trying to make, I think, is that your data design has to be driven by the way the data is going to be used. If you wanted a page which showed all products for a designer, then you might want to build that list in advance for each designer too. Or not, again taking response time into consideration. You should really start out with the simplest possible design, then add complications as necessary in response to requirements.
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic