mardi 18 octobre 2016

How to design a class for a program?

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:

  1. How do we design the solution for a problem where we may need to use one or more Classes?
  2. How do we choose what classes to build for a problem?
  3. How do we make sure our class design is efficient?
  4. 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