I have a general question: What should be done when an object’s behavior should change according to context? (Please note that this is regarding SQL and not C#, but I could really use ideas here)
For example, the Search class, let’s call it “SearchObject”. This SearchObject gets a search term and returns 5 results from Google. It does this and this only.
Now I have a new requirement: if the object is called from a certain context, it appends results from another search engine. For example, if I call a search from a web page, this object should bring 10 results: first 5 from Google, last 5 from Bing. If it’s called from a console application, it should bring the last 5 results from AltaVista.
How do I keep this object’s behavior according to the OOP principles AND get the desired result?
(The implementation will be in SQL, so I can’t use the design patterns I know in C#…)
Thanks!
Obviously its much more common to do this in elsewhere, but if you’re keeping the behavioral logic in SQL you could do one of the following
Use a parameter
just pass something to the procedure. For Example
However this requires your applications to have knowledge of this parameter, and this may not be what you’re looking to do.
Use something about the session
You could also use information about the session. For example
APP_NAME()Use a specific user
Another option is to dole out the user names to the context they’re going to use and then use
CURRENT_USERCreate Proc sp_Search (@Search varchar(500))
AS
Honestly I would rather allow any behavior by any application (The Mechanism) and then configure the policy for each application, rather than tying the Mechanism and Policy together (as above)