Object-Oriented Programming and Classes
Object-Oriented Programming and Classes
OoP/ Slide 2 Motivation Basic, built-in, pre-defined types: char, int, double, Variables operations on them nt a b c=atb a mod b More complicated, user-defined types: classes Variables objects Types >classes
OOP / Slide 2 Basic, built-in, pre-defined types: char, int, double, … Variables + operations on them int a, b,c; c=a+b; c=a mod b; … More complicated, user-defined types: classes Motivation Variables → objects Types → classes
OoP/ Slide 3 procedural programming a sequence of procedures int a, b, c; CC: a=1(x) b=2(); f20 C=f3(z); } Class A int f20 Class B int f30 Int f20 Class c Object oriented programming: a sequence of 'objects'!
OOP / Slide 3 int main() { int x,y,z; int a,b,c; a=f1(x); b=f2(y); c=f3(z); … } int f1() { } int f2() { } int f3() { } int main() { A a; B b; C c; a.f1(); b.f2(); c.f3(); … } Class A { Int x; Int f1(); } Class B { Int y; Int f2() } Class C { Int z; Int f3(); } procedural programming: a sequence of ‘procedures’ Object oriented programming: a sequence of ‘objects’!
OoP/ Slide 4 Variables objects MotivationTypes → classes Procedural programming LOW-level. closer to hardware More intuitive less abstract More 'action’ oriented Focus on 'action, procedure, 'method Procedure-oriented Object-oriented programming High-level More abstract Focus on what to do' not on how to do In the implementation of OOP, we still need sound procedure programming' skills
OOP / Slide 4 Motivation Variables → objects Types → classes Procedural programming: Low-level, closer to hardware More intuitive, less abstract More ‘action’ oriented Focus on ‘action’, ‘procedure’, ‘method’ Procedure-oriented Object-oriented programming: High-level More abstract Focus on ‘what to do’ not on ‘how to do’ In the implementation of OOP, we still need sound ‘procedure programming’ skills!
OoP/ Slide 5 Motivation We want to build user-defined(and"smart) objects that can answer many questions(and perform various actions) What is your temperature? What is your temperature in Fahrenheit? What is your humidity?” Print your temperature in Celsius What is your wish?
OOP / Slide 5 Motivation We want to build user-defined (and “smart”) objects that can answer many questions (and perform various actions). “What is your temperature?” “What is your temperature in Fahrenheit?” “What is your humidity?” “Print your temperature in Celsius.” What is your wish?