I have a function which saves a message in a database. There are different scenarios for saving messages based on types. For example I have Save Message, Save Message for Repair, and Save Message from XML.
Would a sensible approach be to create a single function with a parameter which specifies the operation type, and to have a switch case to choose between calling three different methods?
I have come up with this so far:
public bool SaveMessage(Message message,
List<Image> images,
List<Attachments> attachments,
string type);
and have three other methods: SaveMessage(), SaveMessageForRepair(), and SaveMessageXml().
Is this a reasonable approach?
Use Strategy Pattern.
http://www.dofactory.com/Patterns/PatternStrategy.aspx