Consider an Eg. of Library Management System, we can have a design where in a student can search for a book based on it's title from the list of books using a function, something like below
[1]
std::vector<std::string> GetBookListBasedOnTitles(std::string title, std::vector<string> books) {
// iterate through list of books and add a book to the result list if it's title is same as the title to be searched.
// Return the result list.
}
or
[2]
shall we make an interface "Search" that will be implemented by "SearchByTitle" class and designate the responsibility of search functionality to that class.
[a] Are there any advantages [2] over [1], if yes, could you please give some scenarios explaining the same ?
[b] Shall we always make interfaces which can then be implemented by other classes to provide functionalities like Search, AddBook, AddMember etc. for the system? The negative which I see in this approach is there would be alot of interfaces for as for every small functionality, we have an interface.
[c] How to decide when to provide an interface for a functionality ?
Aucun commentaire:
Enregistrer un commentaire