Before I explain the list of questions I wanted to point out the motivation for this question.
Motivation: Whenever a complicated problem is given in a competitive programming site like HackerRank or TopCoder which involves graph/tree traversals,Dynamic Programming, we generally tend to use standard traversal algorithms but define certain classes and objects. This makes our problem easier to solve and easier to read/understand/visualize. For example certain classes for Graph Traversal Problems would be Node, Graph:
class Node{
//with Functions like
getNode();
setNode();
}
class Graph{
//with Functions like
createGraph();
setNode();
getNode();
}
I understand that defining classes would be very broad and their utility in the problem solving would also vary. This brings me to my question.
Question/Concern:
- How do we design the solution for a problem where we may need to use one or more Classes?
- How do we choose what classes to build for a problem?
- How do we make sure our class design is efficient?
- Are there certain problems where the same class designs are applicable?
When I use the term Class Design, I mean what are the combinations of classes used and the functions defined in the class.
Apologies, if the content is really broad. I would appreciate any thoughts,edits and ideas. Thank you!
Aucun commentaire:
Enregistrer un commentaire