Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIT 590 Intro to Programming Lecture 10 (object oriented programming)

Similar presentations


Presentation on theme: "CIT 590 Intro to Programming Lecture 10 (object oriented programming)"— Presentation transcript:

1 CIT 590 Intro to Programming Lecture 10 (object oriented programming)

2 Agenda Objects MVC

3 Objects/Services A program written in an object oriented paradigm will have Classes Each class providing service methods that are utilized by other classes Metaphorically speaking we are passing messages to service providers

4 A stack object When you instantiate a stack object you will get access to methods like Push – put an element onto the top of the stack Pop – pop the first element out of the stack

5 Distinction between class and instance Class is the template An instance is a specific example of that template An example with stacks

6 Creating a calculator using stacks Reverse polish notation Clearly we need a class that implements stack functionality Given that we have implemented stacks, we can write what we generically call calc code Module dependencies (we’ve probably seen this before by now?)

7 Object oriented programming The stack object was not concerned with the fact that it was going to eventually be used to solve reverse polish notation problems The reverse polish calculator engine is not concerned with the fact that the user is going to be entering operators and operands split by space Advantages Understanding the program is easier Testing! General purpose classes like stacks can be reused

8 Model view separation Separate the actual calculation implementation from the user interface Many views can exist for the same model GUI, text based inputs, different formats …

9 Infix calculator Building a wrapper class on top of the RPNCalculator Note how both the RPNCalculator and the Stack class are being used in this case

10 Discovering objects Usage of CRC – class responsibility collaborator pattern Write the nouns and verbs that are part of the application Each noun defines an entity Verbs matched up with a who for a class

11 Duck Typing Class implementations are implementing the abstract concept of a type Any object that implements the members and the functions that are required will be considered to be of the appropriate type

12 Encapsulation and properties Usage of getters and setters instead of directly accessing the properties on an object Nothing in the python language will really prevent you from doing the direct access though The underscore convention is used for data that should rarely (if ever) be directly accessed You can remove the function call syntax by using property syntax property(getter function name, setter function name) Use None if you want to ensure that there is no getter or no setter

13 Summary Recursion Throwing exceptions IDLE debugger


Download ppt "CIT 590 Intro to Programming Lecture 10 (object oriented programming)"

Similar presentations


Ads by Google