Classes, Objects, and Interfaces CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.3 © Mitchell Wand, 2012-2014 This work is licensed under a Creative.

Slides:



Advertisements
Similar presentations
Templates CS 5010 Program Design Paradigms “Bootcamp” Lesson
Advertisements

Real State vs. Simulated State CS 5010 Program Design Paradigms "Bootcamp" Lesson 11.3 © Mitchell Wand, This work is licensed under a Creative.
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Function Composition CS 5010 Program Design Paradigms “Bootcamp” 1 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
The Function Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Midterm Review CS 5010 Program Design Paradigms “Bootcamp” Lesson 9.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Interfaces CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.2 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
Linear Search CS 5010 Program Design Paradigms “Bootcamp” Lesson 9.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
Language Issues for Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.3 © Mitchell Wand, This work is licensed under a Creative.
Case Study: Free Variables CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Ormap, andmap, and filter CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Function Composition CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
Structural Decomposition CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.1 © Mitchell Wand, This work is licensed under a Creative Commons.
Stateful Objects and Stable Identities CS 5010 Program Design Paradigms "Bootcamp" Lesson 11.2 © Mitchell Wand, This work is licensed under a.
Trees CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.2 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
Mutually-Recursive Data Definitions CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.4 © Mitchell Wand, This work is licensed under a Creative.
From Templates to Folds CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
Foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA © Mitchell.
Kindergarten Math Janelle Ward. Lesson Objectives Students will be able to identify and describe shapes 100% of the time. Students will be able to identify.
Patterns of Communication Between Objects CS 5010 Program Design Paradigms "Bootcamp" Lesson 11.1 © Mitchell Wand, This work is licensed under.
Solving Your Problem by Generalization CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.1 © Mitchell Wand, This work is licensed under a.
Invariants and Performance CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.6 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
The Function Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Examining Two Pieces of Data CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative.
Classes, Objects, and Methods CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.1 © Mitchell Wand, This work is licensed under a Creative.
The Design Recipe using Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.5 © Mitchell Wand, This work is licensed under a Creative.
Design Strategies 1: Combine Simpler Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed.
The Point of This Course CS 5010 Program Design Paradigms “Bootcamp” Lesson 0.1 © Mitchell Wand, This work is licensed under a Creative Commons.
Using Inheritance to Share Implementations CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1 © Mitchell Wand, This work is licensed under.

Design Strategies 2: Using a template CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.1 © Mitchell Wand, This work is licensed under a Creative.
More examples of invariants CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative.
Generalizing Over Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Thank you for using this pre-visit resource. We believe this will help strengthen student learning leading up to and during your gallery visit. Due to.
Solving Your Problem by Generalization CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.1 © Mitchell Wand, This work is licensed under a.
The Design Recipe using Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative.
Lists vs. Structures CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
The DD  OO Recipe CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.4 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
Organization of This Course CS 5010 Program Design Paradigms “Bootcamp” Lesson 0.2 © Mitchell Wand, This work is licensed under a Creative Commons.
= 5 = 2 = 4 = 3 How could I make 13 from these shapes? How could I make 19 from these shapes? STARTER.
Halting Measures and Termination Arguments CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Non-Empty Lists CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Using Inheritance to Share Implementations CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under.
Using the List Template CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Using the List Template CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.2 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Functions vs. Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
More linear search with invariants CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before.
Solving Your Problem by Generalization CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under.
How many …?. What shape can you see? I can see some _____. Q1 Q1 stars.
Classes, Objects, and Interfaces CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative.
Welcome Thank you for using this pre-visit resource. We believe this will help strengthen student learning leading up to and during your gallery visit.
More Recursive Data Types
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.2
Halting Functions for Tree-Like Structures
CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.1
From Templates to Folds
The Different Kinds of Data
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.3
Follow Directions with Colors and Shapes
Solving Your Problem by Generalization
Here are four triangles. What do all of these triangles have in common
Contracts, Purpose Statements, Examples and Tests
ormap, andmap, and filter
PATTERNS.
Working with images and scenes
Examining Two Pieces of Data
Presentation transcript:

Classes, Objects, and Interfaces CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.3 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Creative Commons Attribution-NonCommercial 4.0 International License 1

Goals for this Lesson In this lesson, we’ll illustrate the relationship between the functional version of the shapes and the object-oriented version. 2

The Big Picture The functional version and the OO version are really the same. They just have the pieces grouped differently. Here are a couple of slides that illustrate what happened. We had 6 little functions to write. Let's see where they wound up in the functional version, and then in the OO version. 3

The Big Picture: Functional my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene define weight: define add-to-scene: When we call weight or add-to-scene, we use a cond expression to determine what kind of shape we were dealing with, so the appropriate code is evaluated. 4

The Big Picture: Classes my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene class circle: class square: class composite: When we invoke a method on an object, the object already knows what class it belongs to, so the correct piece of code is evaluated directly. We no longer need to write a cond. 5

Functional vs. OO organization Functional:SquareCircleComposite weight add-to-scene OO:SquareCircleComposite weight add-to-scene Here's another way of visualizing the same thing. Here we have six small rectangles corresponding to our six pieces of functionality. In the functional organization, all the pieces corresponding to weight are written together (symbolized here by outlining them in red), and all the pieces corresponding to add-to-scene are written together (outlined in green). In the object-oriented organization, all the pieces for square are written together (the red outline in the lower table), all the pieces for circle are written together (the orange outline), and all the pieces for composite are written together (the purple outline). 6

Adding a New Data Variant Functional:SquareCircleCompositeTriangle weightNew code add-to-sceneNew code OO:SquareCircleCompositeTriangle weightNew code add-to-sceneNew code If we add a new kind of data, such as a triangle, what will we need to change? We will need 2 pieces of code: to compute the weight of a triangle and to display it. In the functional organization, the two cells correspond to different portions of our file, so we will need to edit two pieces of our file: the weight function and the add-to-scene function. In the object-oriented organization, we will add the two pieces in a single place in our file: the new triangle class. 7

Adding a New Operation Functional:SquareCircleComposite weight add-to-scene movenew code 1new code 2new code 3 OO:SquareCircleComposite weight add-to-scene movenew code 1new code 2new code 3 If we add a new operation such as move, what needs to change? In the functional organization, we add the new code in a single function definition, the function move, symbolized by the blue outline above. In the object-oriented organization, we must add a move method in each of our classes. 8

Extensibility Functional Org.O-O Org. New Data Variant requires editing in many places all edits in one place New Operation all edits in one placerequires editing in many places 9

What's the tradeoff? Object-oriented organization is better when new data variants are more likely than new operations. Functional organization is better when new operations are more likely than new data variants. In the real world, you may not have a choice: – this decision is up to the system architects – or may need compatibility with an existing system There are ways to get the best of both worlds – but these are beyond the scope of this course – this is called "the expression problem" 10

Summary You should now be able to draw diagrams that explain the organization of O-O programs vs. functional programs. 11

Next Steps Review examples 10-4 through 10-8 in the examples folder. If you have questions about this lesson, ask them on the Discussion Board Go on to the next lesson 12