Download presentation
Presentation is loading. Please wait.
Published byNora Stevens Modified over 8 years ago
1
CIT 590 Intro to Programming Object oriented programming
2
Agenda Finish up functional programming More on classes More discussion of style
3
Sieve example Functional programming lends itself to recursion really easily Erasthothenes algorithm for getting rid of composite numbers in a list of increasing numbers beginning with the number 2 An ancient algorithm for finding prime numbers From any list of increasing numbers remove the multiples of any number in the list Easy for list of size 1 Can I do this recursively???
4
The 3 argument version of the reduce function We have already seem reduce(function, list) There is a 3 argument variant which is Reduce(function, list, identity element/first element for the process Sorting examples Define insertion of an element into a sorted list Now use a reduce operation
5
Quicksort List comprehension = badass Quicksort.py - how to do something like quickSort in very few lines of code
6
More examples of classes Stacks Last in first out datastructure Python does not have stacks but you can use a list to simulate stacks See stacks.py in the repository
7
Object oriented design Think of your problem as a bunch of objects interacting with each other The way that an object interacts with another object is via the methods Library example A library is an object Within the library object I need to have books … make that another object These books get issued by patrons … make a patron object The library is the one that knows about all the patrons and all the books. An instance of a book does not need to care about patrons.
8
Inheritance revisited How to call a method of your parent class? What if the parent class does not want to define a method completely? We will explore this concept more fully when we do abstract classes in Java animals.py has examples of this
9
More examples of refactoring We’ll refactor refactoringExample.py Main goal = showing you how to declutter the main function
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.