Learner
Learner

Reputation: 4751

Could you please suggest better design?

Following is the scenario.

I have something called as Domain which can have multiple States (Statekey-Statevalue pair) in it. The same StateKey can be present in multiple domains but with different StateValue.

e.g. StateKey named 'EconomicCapital' may be present in Domains like 'England', 'America' with values 'London', 'Washington' respectively.

Classes corresponding to these are in common library which can be consumed at client or service side as required.

I have a winform application in which I can select a specific domain. In any string, wherever I encounter any StateKey, I want to replace it by its StateValue for the selected domain.

I can think of following designs:

  1. Establish composition relationship. Domain can be composed of the States. So when I want a StateValue of any StateKey, I can get the object of the required domain and can extract StateKey from the States collection composed in it.

But there can be large number of instances where StateKey would be used, I do not think this approach is quite good snce it requires finding Domain object from the collection of domains and iterating through its State collection to find particular key.

OR

  1. Maintain a static collection which can hold all StateKeys in different domain. When I want particular StateKey I can simply lookup in this collection.

Could you please advice me which approach is more appropriate? Will there be any other approach/design?

(If the logic is implemented at service side; not just one winform application but many such applications can access it.)

Upvotes: 1

Views: 159

Answers (2)

P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

Is this just a "thought project"/homework? Domain > State > StateValue relationships have to do something to become a class and use design patterns. This appears to be just a set of lookup operations. You may be better of using LINQ or a database.

Upvotes: 0

Jaime
Jaime

Reputation: 6814

What about something like

Dictionary<domain, Dictionary<statekey, statevalue>()

You could then find the key value pairs from the domain, and get the value from that.... Or am I missing something in your question?

Upvotes: 3

Related Questions