• 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

Need info on how to design

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

This is a specific interview question that my friend got while attending an interview.
Sharing it here to understand different views on how to design the system.
Here goes the question...

There is a node/site named "International Recipes"
It has 3 branches namely "India", "Australia" and "Canada"
Each of these have three branches namely "Vegetarian" and "Non-Vegetarian"
Under Vegetarian there are two branches namely "Potato Recipes" and "Tomato Recipes"
Under Non-Vegetarian, there are two branches namely "Chicken Recipes" and "Mutton Recipes"

Each of these nodes, including the primary node can have subscribers.
If any recipe is added to any one node/branch, immediately subscriber of the relevant node should get intimation.

How do we design a java code for this?

Regards,
Sriraam
Recipe_Design.JPG
[Thumbnail for Recipe_Design.JPG]
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So here is my design:

Then anything which can be subscribed has to implement Subscribable. So here goes the interface


Then I would consider that the countries can be grouped into Regions and each of the country can actually have a list of recipes available in that country. But before that, we need to have a Recipe class, each of the recipes can extend this class. As of now I am thinking that there's nothing unique or different between veg and non veg recipes except that each of the recipe will have it own method of preparation. So I would consider having an attribute to indicate whether its a veg or non veg. Also anyone can subscribe to the recipe. So it goes on something like:

Or another possible approach would be to use Marker interface for indicating if its a Vegetarian or NonVegetarian.

Then there is Region, India extends Region, Australia extends Region, Canada extends Region. And each region can also be subscribed. And each region would have a list of its own recipes, so we can define them something like:



The advantage of using Subscribable interface is that being able to Subscribe and being a recipe are 2 different things, so merging them into one would be like having multiple responsibilities for a single class. Also recipes being arranged in a hierarchy of countries would cause problems if the same recipe would be used in different countries. So I chose using composition of recipes in Countries over putting them in a hierarchy. Moreover Recipe and Country dont confirm to IS-A principle.

This would be my first cut design. Can be improved as and when we get more details about the application.
reply
    Bookmark Topic Watch Topic
  • New Topic