Advertisement
bojjenclon

Procedural vs OOP

Jul 11th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. Object Oriented:
  2. public class Tree
  3. {
  4. private int m_leafCount;
  5. private string m_season;
  6. private float m_nutrientLevel;
  7.  
  8. public Tree(TreeType p_type)
  9. {
  10. TreeDataBase l_database = TreeDataBase.GetInstance();
  11.  
  12. Initialize(l_database.GetValues(p_type));
  13. }
  14. }
  15.  
  16. void main()
  17. {
  18. Tree l_appleTree = new Tree(TreeType.Apple);
  19. Tree l_orangeTree = new Tree(TreeType.Orange);
  20. }
  21.  
  22. ***
  23.  
  24. Procedural:
  25. void main()
  26. {
  27. FileHandler l_database = new FileHandler("treeDatabase.db");
  28.  
  29. // tree1
  30. int l_leafCount1;
  31. string l_season1;
  32. float l_nutrientLevel1;
  33.  
  34. // tree2
  35. int l_leafCount2;
  36. string l_season2;
  37. float l_nutrientLevel2;
  38.  
  39. while (!l_database.eof())
  40. {
  41. string l_currentLine = l_databse.getLine();
  42.  
  43. if (indexOf(l_currentLine, "apple") > 0)
  44. {
  45. string[] l_splitLine = splitString(l_currentLine, ",");
  46.  
  47. l_leafCount1 = atoi(l_splitLine[0]);
  48. l_season1 = l_splitLine[1];
  49. l_nutrientLevel = atof(l_splitLine[2]);
  50. }
  51. else if (indexOf(l_currentLine, "orange") > 0)
  52. {
  53. string[] l_splitLine = splitString(l_currentLine, ",");
  54.  
  55. l_leafCount2 = atoi(l_splitLine[0]);
  56. l_season2 = l_splitLine[1];
  57. l_nutrientLeve2 = atof(l_splitLine[2]);
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement