Programming Paradigms Seminar 2

1,034 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,034
On SlideShare
0
From Embeds
0
Number of Embeds
129
Actions
Shares
0
Downloads
41
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • As we are famillar with OO
  • An OO paradigm view everything in this world as objects. Like on Earth, we have objects of human, animal and building.
  • Deals with what a class know or does… it includes the responsibilities, attributes and methodsThe Vet see the different part of the cats in terms of structure things like what it likes to do or likes to eat does not matterThe old lady see the cat as her pet will more likely be interested in what the cat like to eat but not the different parts of the cat body
  • Deals with what a class know or does… it includes the responsibilities, attributes and methodsThe Vet see the different part of the cats in terms of structure things like what it likes to do or likes to eat does not matterThe old lady see the cat as her pet will more likely be interested in what the cat like to eat but not the different parts of the cat body
  • Deals with what a class know or does… it includes the responsibilities, attributes and methodsThe Vet see the different part of the cats in terms of structure things like what it likes to do or likes to eat does not matterThe old lady see the cat as her pet will more likely be interested in what the cat like to eat but not the different parts of the cat body
  • Programming Example-> Keypad -> Example contain alphabet, numeric, operator, function-> NUMPAD -> ATM need only number only there for only takes in Numeric
  • Abstraction tells us that we need this function for the object. Encapsulation deals with how you intend to modularize the features. It deals with how the functions is being compartmentalize. It like a black box what is being done is not known to the rest of the system
  • PublicPrivate
  • Public attributes like studentID and telNum can be edited directly. However the will be
  • Inheritance [XT]A mechanism that reuse existing code and extend to new classesGiven this 2 classes, they have similar properties between them.No doubt, we can develop both classes independently can get them running (probably can just create a student class first, then copy the code and modify a bit for the creation of Professor class)However, if u made an error on driveVehicle method, got to modify code on both sideCan only inherit protect and public attributes and methods but not private ones. A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass.
  • Inheritance [XT]A mechanism that reuse existing code and extend to new classesGiven this 2 classes, they have similar properties between them.No doubt, we can develop both classes independently can get them running (probably can just create a student class first, then copy the code and modify a bit for the creation of Professor class)However, if u made an error on driveVehicle method, got to modify code on both sideCan only inherit protect and public attributes and methods but not private ones. A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass.
  • Inheritance Approach:Encapsulate the similar properties into another class “Person” can let “Student” class and “Professor” extends from it.Student “is a” person. Professor “is a” person.All the properties and behaviors of the base class Person, are inherited.Base Class: Person, Derived Class: Student, ProfessorAnother way to look at this UML is Student and professor is a specialization of Person ClassAnd Person class is a generalization of student class or professor class.
  • method
  • Each job profession in a company have different salaries (each have their own calculation of pay per month, per year etc).If you want to call the computeSalary() of a CEO, you would have to specifically call from each individual class:
  • With polymorphism, each classes are treated the same way.The programmer no need to be concerned about the precise type of the class but just to call the method work() on a generalized class. The OO system will then determine its class type at runtime, and invoke the correct work() accordingly.
  • Generalize the 3 classes into one abstract class, containing the abstract method work().Since person is the base class, the variable object of type person and be store with type engineer, accountant and professor subsequently.Programmer does not have to know exact class type when coding. It will be determined at run-time.
  • When we have a list that contains different objects of different professions, we can loop through the list and call the work method directly without the need to check the type of the object. At run-time, the object will be connected to the appropriated method and this is known as dynamic bindingSignificantly reduces the development effort.
  • Store derived class in base class and call the common method. At runtime, the system will locate the actual implementation of method at corresponding class.computeDiscount method is used to calculate the percentage of discount for each item given a promotional event e.g. Great Singapore Sales, year end sales.The discount can be of storewide discount => method in ItemThe discount can be of different type discount, e.g. 10% for all hardwares => the method in the hardware class overrides the computeDiscount at ItemThe discount can be of same type but different kind, e.g. 10% for all software only=> the method in the Software class overrides the computeDiscount at Multimedia.
  • Programming Paradigms Seminar 2

    1. 1. Seminar 2 : The state of the practice<br />Programming Paradigms<br />[The Paradigms - Group 2]<br />
    2. 2. Most of us will be in I.T Industry<br />2<br />
    3. 3. Being experts in a paradigmcan help us climb up the corporate ladder<br />3<br />
    4. 4. Object-Oriented Paradigm<br />4<br />
    5. 5. Everyone knows how to use Object-Oriented Programming Languages<br />5<br />Objective-c<br />Java<br />Javascript<br />C#<br />PHP<br />C++<br />Python<br />
    6. 6. But does knowing OO programming languagesequivalent to knowing OO paradigm?<br />6<br />
    7. 7. Let us be Experts in OO Paradigm And overcome its limitations<br />7<br />
    8. 8. Quest: Mastery of OO<br />
    9. 9. 9<br />Training : OO Characteristics<br />
    10. 10. Let’s Recap:What is Object-Oriented Paradigm?<br />10<br />
    11. 11. Recap<br />11<br />View everything as objects which<br />Behaviors<br />Properties<br />Human<br />“Alice”<br />Name:<br />Gender:<br />Size:<br />Eye _colour:<br />Shopping()<br />Animal<br />Building<br />“Bob”<br />
    12. 12. 12<br />OO Characteristics? You know that…<br />But have you misunderstood any of these concepts?<br />
    13. 13. 13<br />Weak OO Model<br />Scenario: Looking for an item in Challenger<br />
    14. 14. 14<br />Weak OO Model<br />Straight OO Modeling<br />
    15. 15. 15<br />Training : OO Characteristics<br />
    16. 16. Characteristics of OO<br />Abstraction: A high level view<br />Eliminate the Irrelevant, Amplify the Essential<br />
    17. 17. Characteristics of OO<br />The Vet Point of View<br /><ul><li> Relevant
    18. 18. Parts of the cat
    19. 19. Etc…
    20. 20. Irrelevant
    21. 21. Favorite Toy
    22. 22. Etc… </li></li></ul><li>Characteristics of OO<br />The Owner Point of View<br /><ul><li> Relevant
    23. 23. Favorite Toy
    24. 24. Etc…
    25. 25. Irrelevant
    26. 26. Scientific Names of the cat’s body parts
    27. 27. Etc… </li></li></ul><li>Characteristics of OO<br />Programming Point of View<br />US Keyboard<br />ATM Keyboard<br />getAlphabet()<br />getNumeric()<br />getFunction()<br />getNumeric()<br />getFunction()<br />
    28. 28. Characteristics of OO<br />Encapsulation<br />Hiding the Unnecessary<br />
    29. 29. Characteristics of OO<br />Programming Point of View<br />Student<br />Student<br />+ StudentID<br />+ CAP<br />- StudentID<br />- CAP <br />Private <br />Public<br />
    30. 30. Main Concepts of OO<br />Programming Point of View<br /><ul><li>Drawbacks
    31. 31. Bypass checking
    32. 32. Breach integrity
    33. 33. Break in code when there is change
    34. 34. Vulnerable to malicious attack</li></ul>Student<br />+ StudentID<br />+ CAP<br />Public<br />
    35. 35. 23<br />Characteristics of OO<br />They might look the similar, but they are not.<br />Father<br />Son<br />Modeling the Similarity<br />
    36. 36. Characteristics of OO<br />Programming Point of View<br />Student<br />Professor<br />name<br />gender<br />address<br />phoneNumber<br />matricNo<br />name<br />gender<br />address<br />phoneNumber<br />staffID<br />driveVehicle()<br />driveVehicle()<br />
    37. 37. Characteristics of OO<br />Student<br />Professor<br />name<br />gender<br />address<br />phoneNumber<br />matrixNo<br />name<br />gender<br />address<br />phoneNumber<br />staffID<br />driveVehicle()<br />driveVehicle()<br />A Better Solution<br />
    38. 38. Characteristics of OO<br />Inheritance is used to express“is a” relationship.<br />Student<br />Professor<br />Person<br />Base Class<br />(Generalization)<br />matricNo<br />staffID<br />name<br />gender<br />address<br />…<br />…<br />driveVehicle()<br />Derived Class<br />(Specialization)<br />
    39. 39. 27<br />Characteristics of OO<br />If you ask different animal to “speak”, they responds in their own way.<br />Same Function Different Behavior<br />
    40. 40. Characteristics of OO<br />Programming Point of View<br />computeSalary()<br />computeSalary()<br />computeSalary()<br />28<br />accountant.computeSalary()<br />CEO. computeSalary()<br />programmer. computeSalary()<br />
    41. 41. Characteristics of OO<br />29<br />Polymorphism treats each instance of different classes the same way within a system.<br />Employee.computeSalary()<br />computeSalary()<br />computeSalary()<br />computeSalary()<br />
    42. 42. Characteristics of OO<br />We can use Inheritanceto apply polymorphism.<br />Employee<br />computeSalary ()<br />Employee object = <br /> new CEO();<br />object.computeSalary();<br />computeSalary()<br />computeSalary()<br />computeSalary()<br />
    43. 43. Characteristics of OO<br />Polymorphism reduce development effort with the help of dynamic binding property.<br />Employee<br />computeSalary ()<br />//people is a list that contains some Accountant, CEO and Programmer objects.<br />for (Employee p :people){<br />p.computeSalary();<br />}<br />computeSalary()<br />computeSalary()<br />computeSalary()<br />
    44. 44. OO Characteristics<br />32<br />
    45. 45. Strong OO Model<br />Reinforce weak OO model with 4 characteristics.<br />
    46. 46. Abstraction<br />Strong OO Model<br /><ul><li> Abstract only relevant information for Multimedia Class</li></li></ul><li>Encapsulation<br />Strong OO Model<br /><ul><li> Protect attributes from any direct access</li></li></ul><li>Inheritance<br />Strong OO Model<br /><ul><li> Extend Multimedia class to more than one class with specialized functionalities</li></li></ul><li>Polymorphism<br />Strong OO Model<br /><ul><li> Apply polymorphism for common method with different implementation</li></li></ul><li>Quest: Mastery of OO<br />
    47. 47. Thank you!<br />End of Presentation<br />

    ×