Design Patterns for Lazy Evaluation

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages – It’s elegant, minimal, can.
1/20 Generalized Symbolic Execution for Model Checking and Testing Charngki PSWLAB Generalized Symbolic Execution for Model Checking and Testing.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Basic OO Technology Technology determines the effectiveness of the approach.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Preliminaries Attendance sheets –I remembered! Survey links –HW1 time survey –Anonymous feedback survey HW discussion (4PM, Commons 9)
Lists We’ve seen an array-based list implementation, the ArrayList. Advantage of an array-based implementation: –fast access to a specific index –typically.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Abstract Factory Design Pattern making abstract things.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
OOP in Introductory CS Stephen Wong and “Zung” Nguyen Rice University Better students though abstraction.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
Data Abstaraction Chapter 10.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Patterns for Decoupling Data Structures and Algorithms Dung “Zung” Nguyen Pepperdine University / University of Houston Stephen Wong Oberlin College
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Huang-Ming Huang, Shih-Ling Chen, Sajeeva Pallemulle.
Module 9. Dealing with Generalization Course: Refactoring.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
CSCI-383 Object-Oriented Programming & Design Lecture 30.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Examples (D. Schmidt et al)
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Strategy Design Pattern
Tail Recursion.
CHAPTER 5 GENERAL OOP CONCEPTS.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Design Patterns for Sorting Teaching something old in a new light
Introduction to Design Patterns
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
State pattern – A logical ‘Finite State Machine’
classes and objects review
Design Patterns for Sorting something old in a new light
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Daniel Amyot and Jun Biao Yan
Design Patterns for Sorting Teaching something old in a new light
Building Java Programs
Higher-Order Procedures
Design Patterns For Sorting
lecture 08, OO Design Principle
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Advanced Java Programming
Data Abstraction David Evans cs205: engineering software
Need for the subject.
DESIGNING YOUR SYSTEM.
Unit 3 Test: Friday.
DESIGN PATTERNS : State Pattern
Streams and Lazy Evaluation in Lisp and Scheme
State Design Pattern Brandon Jacobsen.
Structural Patterns: Adapter and Bridge
Combining Compile-Time and Run-Time Components
Strategy Design Pattern
Introduction to Data Structure
Chapter 8, Design Patterns Introduction
Presentation transcript:

Design Patterns for Lazy Evaluation Ning Zhu Jan 22 2016

What is Lazy Evaluation Concept Expression is only evaluated when it's "actually needed” Application/Implementation Often represented in functional programming Why do it in OO? Practically useful -> ⬇ space complexity Good practice/demo for abstract thinking

How to do LE in OO? Design Goals Design Methods Example (Pros & Cons)

Design goal -Flexible, Extendible, Reuseable the LE structure (e.g. LRS) appears as if it has all the elements, to all algos the first and the rest can transit from lazy to eager misc: the evaluated portion performs as efficient as a regular eager structure No modification or recompilation for existing code  Existing algorithms behave the same for ordinary finite structure and lazy structure Because it’s dynamic re-classification -> state pattern

Design: Goals  Methods The invariant: Runtime change of behaviors: lazy -> eager Not known to the outside world ⬇ Dynamic re-classification State Design Pattern the LE structure (e.g. LRS) appears as if it has all the elements, to all algos the first and the rest can transit from lazy to eager  misc: the evaluated portion performs as efficient as a regular eager structure how to design, what to choose? Find the invariant and the unique thing of lazy evaluation => a behavior of transition => behaviorally different, not known to the outside world

Design: Methods Lazy->Eager, a state transition in State Design Pattern LRS: behaviorally similar (transition across states from element to element) -> good candidate for modifying Minimal change = Add a LazyState? \ Invariant: transitioning Variant: the way the transition LRS: Empty to Non-Empty (Eager) LazyEval: LazyNonE -> NonE

Lazy->Eagar Specific Further Design Delegate LE-specific transitioning (variant) to state LRStruct IAlgo Lazy->Eagar Specific Decorator/Wrapper IAlgo has no nextLRS, be verbatim! jumped over how to do decorator, wrong! don't jump over logic links! the steps will suggest what design to use for the next step Regular LRStruct behavior /operation

Get the rest of LRS----> get a LRS (Lazy) End of Design? No… Minimal change of existing framework (e.g. LRStruct) -> Good OO design != let client play with encapsulated constructor Get the rest of LRS----> get a LRS (Lazy)

End of Design? No… Minimal change of existing framework (e.g. LRStruct) Good OO design Information hiding Factory: This is a finite factory

Example- Create a list of prime numbers with Sieve’s Algo Demo

Overview Lazy Evaluation Flexible Reuseable Extendible Factory No need to touch existing framework Flexible Reusable Factory Overview Lazy Evaluation State Lazy Evaluation Flexible Reuseable Extendible Desing first, then implementation. Don’t jump to implementations in the middle to check what’s available & modify my design based on it  identify the right thing first! Then figure out the optimal & realistic way to do it Show how prime number works on Wednesday Decorator Union Extendible …

Example Create a lazy list of monotonically Incremented integers: Cons Overhead – initialization and transition