jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Tight Coupling problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tight Coupling problem " Watch "Tight Coupling problem " New topic
Author

Tight Coupling problem

Gordy Bone
Ranch Hand

Joined: Feb 25, 2007
Posts: 31
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


SCJP 5, SCWCD 5
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Just to add another spanner in the works, can a product belong in more than one product grouping?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Gordy Bone
Ranch Hand

Joined: Feb 25, 2007
Posts: 31
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
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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!
Gordy Bone
Ranch Hand

Joined: Feb 25, 2007
Posts: 31
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18124
    
    8

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.
Gordy Bone
Ranch Hand

Joined: Feb 25, 2007
Posts: 31
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
Bartender

Joined: Oct 14, 2005
Posts: 18124
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tight Coupling problem
 
Similar Threads
disadvantage of inheritance
Coupling
Tight Coupling
IBM Test: Coupling question
OO Concepts - Encapsulation, Cohesion, Coupling