Seminar 2 : The state of the practiceProgramming Paradigms[The Paradigms - Group 2]
Most of us will be in I.T Industry2
Being experts in a paradigmcan help us climb up the corporate ladder3
Object-Oriented  Paradigm4
Everyone knows how to use Object-Oriented Programming Languages5Objective-cJavaJavascriptC#PHPC++Python
But does knowing OO programming languagesequivalent to knowing OO paradigm?6
Let us be Experts in OO Paradigm And overcome its limitations7
Quest: Mastery of OO
9Training : OO Characteristics
Let’s Recap:What is Object-Oriented Paradigm?10
Recap11View everything as objects whichBehaviorsPropertiesHuman“Alice”Name:Gender:Size:Eye _colour:Shopping()AnimalBuilding“Bob”
12OO Characteristics? You know that…But have you misunderstood any of these concepts?
13Weak OO ModelScenario: Looking for an item in Challenger
14Weak OO ModelStraight OO Modeling
15Training : OO Characteristics
Characteristics of OOAbstraction: A high level viewEliminate the Irrelevant, Amplify the Essential
Characteristics of OOThe Vet Point of View Relevant
Parts of the cat
Etc…
 Irrelevant
Favorite Toy
Etc… Characteristics of OOThe Owner Point of View Relevant
Favorite Toy
Etc…
 Irrelevant
Scientific Names of the cat’s body parts
Etc… Characteristics of OOProgramming Point of ViewUS KeyboardATM KeyboardgetAlphabet()getNumeric()getFunction()getNumeric()getFunction()
Characteristics of OOEncapsulationHiding the Unnecessary
Characteristics of OOProgramming Point of ViewStudentStudent+ StudentID+ CAP- StudentID- CAP Private Public
Main Concepts of OOProgramming Point of ViewDrawbacks
Bypass checking
Breach integrity
Break in code when there is change
Vulnerable to malicious attackStudent+ StudentID+ CAPPublic
23Characteristics of OOThey might look the similar, but they are not.FatherSonModeling the Similarity
Characteristics of OOProgramming Point of ViewStudentProfessornamegenderaddressphoneNumbermatricNonamegenderaddressphoneNumberstaffIDdriveVehicle()driveVehicle()
Characteristics of OOStudentProfessornamegenderaddressphoneNumbermatrixNonamegenderaddressphoneNumberstaffIDdriveVehicle()driveVehicle()A Better Solution
Characteristics of OOInheritance is used to express“is a” relationship.StudentProfessorPersonBase Class(Generalization)matricNostaffIDnamegenderaddress……driveVehicle()Derived Class(Specialization)
27Characteristics of OOIf you ask different animal to “speak”, they responds in their own way.Same Function Different Behavior

Programming Paradigms Seminar 2

Editor's Notes

  • #5 As we are famillar with OO
  • #12 An OO paradigm view everything in this world as objects. Like on Earth, we have objects of human, animal and building.
  • #17 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
  • #18 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
  • #19 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
  • #20 Programming Example-> Keypad -> Example contain alphabet, numeric, operator, function-> NUMPAD -> ATM need only number only there for only takes in Numeric
  • #21 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
  • #22 PublicPrivate
  • #23 Public attributes like studentID and telNum can be edited directly. However the will be
  • #25 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.
  • #26 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.
  • #27 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.
  • #28 method
  • #29 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:
  • #30 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.
  • #31 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.
  • #32 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.
  • #38 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.