-1

My application manages fruit records. The application supports different types of data sources. Each fruit has a unique id in the data source. Uniqueness across data sources is not guaranteed because I don't have control over those ids.

I have created a class FruitSourceManager{} that allows we to configure (add/remove) the different fruit sources in my application.

I also have class BasketFruitSource{} class CartFruitSource{} class TruckFruitSource{} each of which implements the interface IFruitSource{}

I have a class FruitManager{} which provides CRUD operations on the Fruit by invoking operations on the IFruitSource

And then I have a class Fruit{} which is used at the business layer and a class FruitDTO{} which is used by the web service.

The application exposes a web service that allows you to read or modify a fruit record. GetFruitById() UpdateFruit()

Is it ok to concatenate the FruitSourceId with the FruitId as a single ID used in the FruitDTO? Or should I use two parameters (FruitSourceId and FruitID) uniquely identifying the fruit?

Are there any pros and cons to one versus the other? Or am I splitting hairs here?

swbandit
  • 1,986
  • 1
  • 26
  • 37
  • 1
    Why is this tagged with c# and java? – Keith Payne Dec 20 '13 at 16:59
  • That's what being used in the project. But yes, this could apply to any other language. I updated the tags. – swbandit Dec 20 '13 at 18:38
  • What is the relation between IFruitSource and Fruit? I would guide my decision on how to manage the Ids based on this information. [Association, aggregation or composition?](http://stackoverflow.com/questions/885937/difference-between-association-aggregation-and-composition) One-to-many or one-to-one? – ericbn Dec 20 '13 at 19:06
  • It's an aggregation. A Fruit belongs to one IFruitSource only but is not tied to the lifecycle of the IFruitSource. – swbandit Dec 20 '13 at 20:13
  • What if a IFruitSource is removed? The related Fruit instances keep living with a NULL IFruitSource? – ericbn Dec 20 '13 at 20:17
  • A Fruit object make sense without a Source. However, it comes from a source and cannot be saved/modified without it. There can be a Fruit without a Source assigned but only temporarily until it is saved into one of the sources. – swbandit Dec 20 '13 at 21:04
  • Can you have multiple BasketFruitSource instances, or just one? The same question applies to CartFruitSource, TruckFruitSource, and whatever other implementations you have... – ericbn Dec 20 '13 at 21:28
  • He removed his tags :) – Cilan Dec 20 '13 at 21:28

1 Answers1

0

It depends what kind of id's you have for the fruits. If your ids are fixed length you could theoretically concatenate them but for incrementing numbers absolutely not

--> 123 + 1 = 12 + 31 etc...

Better ID them yourself if you cant influence your suppliers ids. who knows what kind of strange id (ordering number?) another supplier will have in the future.

fixagon
  • 5,506
  • 22
  • 26