Concurrency Rules Fall 2010 UVa David Evans cs2220 Engineering Software Picture by Jonathan Dilorenzo Menu PS4 Concurrency ObjectOriented Programming PS5 Designs Throughout the Day 1 Blanton James ID: 330022
Download Presentation The PPT/PDF document "Class 16:" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Class 16:
Concurrency Rules
Fall 2010UVaDavid Evans
cs2220: Engineering Software
Picture by Jonathan
DilorenzoSlide2
Menu
PS4ConcurrencyObject-Oriented Programming
PS5 Designs [Throughout the Day]1. Blanton, James Kalish, Michael2. Borja, Joseph Oh, Uyn Noh, Brian3. Brown, Jeremy Hearn, Charles4. Chen,
Jiamin Sparkman, Elisabeth Sun, Yixin5. Dewey-Vogt, Michael Lopez, Erik6. Dilorenzo, Jonathan Featherston
, Joseph
7.
Dollhopf
,
Niklaus
Marion, John
8. Herder, Samuel Wallace, AlexanderSlide3
Substitution Principle
public class Tree { public Tree getChild (
int n) // REQUIRES: 0 <= n < children.length // EFFECTS: Returns the Tree that is the nth leftmost child // of this. NOTE: the rep is exposed!public class BinaryTree extends Tree {
// OVERVIEW: A BinaryTree is a mutable tree where the nodes are // int values and each node has zero, one or two children. @Override
public
BinaryTree
getChild
(
int
n)
// REQUIRES: 0 <= n < 2 // EFFECTS: If this has at least n children, returns a copy of the // BinaryTree that is the nth leftmost child of this. Otherwise, // returns null.
Does
pre
Tree
imply
pre
BinaryTree
?Slide4
Substitution Principle
public class Tree { public Tree getChild (
int n) // REQUIRES: 0 <= n < children.length // EFFECTS: Returns the Tree that is the nth leftmost child // of this. NOTE: the rep is exposed!public class BinaryTree extends Tree {
// OVERVIEW: A BinaryTree is a mutable tree where the nodes are // int values and each node has zero, one or two children.
@Override
public
BinaryTree
getChild
(
int
n) // REQUIRES: 0 <= n < 2 // EFFECTS: If this has at least n children, returns a copy of the // BinaryTree that is the nth leftmost child of this. Otherwise,
// returns null.
Does
0 <= n <
children.length
imply 0 <= n < 2?
When
children.length
<= 2, yes!Slide5
public class Tree {
public Tree getChild (int n) // REQUIRES: 0 <= n < children.length // EFFECTS: Returns the Tree that is the nth leftmost child
// of this. NOTE: the rep is exposed!public class BinaryTree extends Tree { // OVERVIEW: A BinaryTree is a mutable tree where the nodes are // int
values and each node has zero, one or two children. @Override public BinaryTree getChild (int n)
// REQUIRES: 0 <= n < 2
// EFFECTS: If this has at least n children, returns a copy of the
//
BinaryTree
that is the nth leftmost child of this. Otherwise,
// returns null.
Does
post
BinaryTree
imply
post
Tree
?Slide6
public class Tree {
public Tree getChild (int n) // REQUIRES: 0 <= n < children.length // EFFECTS: Returns the Tree that is the nth leftmost child
// of this. NOTE: the rep is exposed!public class BinaryTree extends Tree { // OVERVIEW: A BinaryTree is a mutable tree where the nodes are // int
values and each node has zero, one or two children. @Override public BinaryTree getChild (int n)
// REQUIRES: 0 <= n < 2
// EFFECTS: If this has at least n children, returns a copy of the
//
BinaryTree
that is the nth leftmost child of this. Otherwise,
// returns null.
Code that “breaks” with subtype:
Tree b1 =
t.getChild
(0);
Tree b2 =
t.getChild
(0);assert b1 == b2;Slide7
PS5 Designs [Throughout the Day]
1. Blanton, James
Kalish, Michael2. Borja, Joseph Oh, Uyn Noh, Brian3. Brown, Jeremy Hearn, Charles4. Chen, Jiamin Sparkman, Elisabeth Sun, Yixin5. Dewey-Vogt, Michael Lopez, Erik6. Dilorenzo, Jonathan
Featherston, Joseph7. Dollhopf, Niklaus Marion, John8. Herder, Samuel Wallace, AlexanderSlide8
Parameterized Filters
Object
FilterPointFilter
NegativeFilter
BlurFilter
MultiFilter
AverageFilter
Purple: abstract classesSlide9
Filter
PointFilter
NegativeFilterBlurFilter
MultiFilter
AverageFilter
ParameterizedFilter
ParameterizedBlurFilter
Option 1:
Filter subtype
ParameterizedFilter
PointFilter
NegativeFilter
BlurFilter
MultiFilter
AverageFilter
Option 2:
public
int
getParameter
();
public abstract
boolean
hasParameter
();
FilterSlide10
Filter
PointFilter
NegativeFilterBlurFilter
MultiFilter
AverageFilter
ParameterizedFilter
IntParameterizedFilter
Option 3:
Interface
StringParameterizedFilter
public class
BlurFilter
extends Filter
implements
ParameterizedFilter
{
private
int
param
;
public void
setParameter
(
int
val
) {
param
=
val
; }
public
int
getParameter
() {
return
param
; }
public String
getPrompt
() {
return “Enter the blurring factor: ”; }
...
}
public interface
ParameterizedFilter
{
public void
setParameter
(
int
val
);
public
int
getParameter
();
public String
getPrompt
();}Slide11
PS5 Designs [Throughout the Day]
1. Blanton, James
Kalish, Michael2. Borja, Joseph Oh, Uyn Noh, Brian3. Brown, Jeremy Hearn, Charles4. Chen, Jiamin Sparkman, Elisabeth Sun, Yixin5. Dewey-Vogt, Michael Lopez, Erik6. Dilorenzo, Jonathan
Featherston, Joseph7. Dollhopf, Niklaus Marion, John8. Herder, Samuel Wallace, Alexander