CSE116 / CSE504 Introduction to Computer Science II Dr. Carl Alphonce

advertisement
CSE116 / CSE504
Introduction to Computer Science II
Dr. Carl Alphonce
343 Davis Hall
alphonce@buffalo.edu
Office hours:
Thursday 12:00 PM – 2:00 PM
Friday 8:30 AM – 10:30 AM
OR request appointment via e-mail
PROFESSIONALISM
Turn off and put away electronics:
cell phones
pagers
laptops
tablets
etc.
© Dr. Carl Alphonce
ROADMAP
Where we’ve been
asymptotic notation
exam Q&A
Today
LRStruct intro
Tuesday evening
exam
Wednesday
make-up exams (NO REGULAR CLASS)
Friday
exam return
LRStruct (continued)
Exam #1
EXAM INFORMATION
Tuesday 3/8, 9:15 PM - 10:15 PM
Abdul-Rashed – Gary Bryan Dos Santos
George – Hoeh
Hollingworth – Kaufmann
Kelley – Laschinger
Latif – Seibold
Shah – Thigale
Thomas – Wilson
Wong – Zogby
NSC 201
NSC 210
NSC 215
NSC 220
NSC 225
NSC 218
NSC 222
NSC 228
© Dr. Carl Alphonce
Where was I?
© Dr. Carl Alphonce
SIGCSE
Association for Computing Machinery
SIGACCESS Membership – Accessible Computing
SIGACT Membership – Algorithms and Computation Theory
SIGAda Membership – Ada Programming
SIGAI Membership – Artificial Intelligence
SIGAPP Membership – Applied Computing
SIGARCH Membership – Computer Architecture
SIGBED Membership – Embedded Systems
SIGBio Membership – Bioinformatics, Comp Bio & Biomed
Informatics
SIGCAS Membership – Computers and Society
SIGCHI Membership – Computer-Human Interaction
SIGCOMM Membership – Data Communication
SIGCSE Membership – Computer Science Education
SIGDA Membership – Design Automation
SIGDOC Membership – Design of Communication
SIGecom Membership – Electronic Commerce
SIGEVO Membership – Genetic and Evolutionary Computation
SIGGRAPH Membership – Computer Graphics and Interactive
Techniques
SIGHPC Membership – High Performance Computing
SIGIR Membership – Information Retrieval
SIGITE Membership – Information Technology Education
SIGKDD Membership – Knowledge Discovery in Data
SIGLOG Membership – Logic and Computation
SIGMETRICS Membership – Measurement and Evaluation
SIGMICRO Membership – Microarchitecture
SIGMIS Membership – Management Information Systems
SIGMM Membership – Multimedia
SIGMOBILE Membership – Mobility of Systems, Users, Data and
Computing
SIGMOD Membership – Management of Data
SIGOPS Membership – Operating Systems
SIGPLAN Print Membership – Programming Languages
SIGSAC Membership – Security, Audit and Control
SIGSAM Membership – Symbolic and Algebraic Manipulation
SIGSIM Membership – Simulation and Modeling
SIGSOFT Membership – Software Engineering
SIGSPATIAL Membership – Special Interest Group on Spatial
Information
SIGUCCS Membership – University and College Computing Services
SIGWEB Membership – Hypertext, Hypermedia and Web
© Dr. Carl Alphonce
Association for Computing Machinery
SIGCSE
SIGCSE – Computer Science Education
© Dr. Carl Alphonce
Association for Computing Machinery
SIGCSE – Computer Science Education
SIGCSE
SIGCSE
(1200-1300)
(Technical Symposium)
ITiCSE
(~300)
(Innovation and Technology in CS Education)
ICER
(~80)
(International Computing Education Research)
DC
(~20)
(Doctoral Constortium)
© Dr. Carl Alphonce
LRStruct
© Dr. Carl Alphonce
Traditional list implementations:
provide a large number of methods – making it
difficult to reuse if less functionality is desired;
provide no means, beyond inheritance, to extend
functionality to suit a specific situation; and
adding functionality requires knowledge of internal
structure of the list.
These implementations are inflexible, and do not
exhibit good OO design.
We will explore a state-based list implementation
which can be easily extended with new functionality.
Goal: have a discussion of desirable characteristics
of software, and software designs to achieve those
characteristics, in the context of a small,
manageable system.
The linked-list implementation we will study now (as well as
the binary tree implementation we will study later) is due to D.
Nguyen and S. B. Wong. Their original papers about
LRStruct and BRStruct:
Nguyen, D. 1998. Design patterns for data structures. SIGCSE Bull.
30, 1 (Mar. 1998), 336-340.
DOI=http://doi.acm.org.gate.lib.buffalo.edu/10.1145/274790.274325
Nguyen, D. and Wong, S. B. 1999. Patterns for decoupling data
structures and algorithms. SIGCSE Bull. 31, 1 (Mar. 1999), 87-91.
DOI=http://doi.acm.org.gate.lib.buffalo.edu/10.1145/384266.299693
Variant/Invariant decomposition*
Design principle which leads to cohesive and
decoupled components
That which is invariant is put into one component
Variant properties/behaviors are factored out into
separate components
Compare this to what we saw with e.g. Observer
pattern:
e.g. decoupling of event generation (invariant) from event
handling (variant)
*Also
referred to as commonality-variability analysis
Point of variation: an interface
One variant
Another variant
Point of variation: an interface
One variant
Another variant
a list = a Linear Recursive Structure
(LRS or LRStruct)
What is a list?
the empty list is a list
a pair whose tail is a list is itself a list
This is a recursive definition! (1) is called the base case, and (2) is
called the recursive case.
Note that traditional implementations do not follow this precise
definition of what a list is:
many have no explicit representation of an empty list
none are recursive on the list; instead they recurse on a list node
This has implications for how the structure can support extension
(see Visitor support, in later slides)
States
A list can therefore be in one of two states:
empty (corresponding to the base case)
non-empty (corresponding to the recursive
case)
The state-based implementation we will
study makes this distinction explicit in the
representation
LRStruct design
Empty vs. NonEmpty state
(look Ma, no NullPointerException!)
An LRS object delegates all calls to its LRS State object
– which can respond to all messages.
Empty and NonEmpty states respond differently.
There is never a null pointer in the structure! (Think about
the implications of this for a while.)
There can be a null pointer in the contents.
if (p == null) {
vs.
do something
}
else {
do something else
}
_state.method()
What is basic (invariant) list
functionality?
insert new item at front
remove item from front
set/get first item (head)
set/get rest (tail)
plus (in Java) methods inherited from
Object (toString, equals, etc)
An empty LRS
LRS<String> a = new LRS<String>();
LRS
a
_state
Empty
Inserting an item into an empty LRS
a.insertFront(“fred”);
LRS
a
_state
Empty
Inserting an item into an empty LRS
a.insertFront(“fred”);
LRS
a
_state
Empty
Inserting an item into an empty LRS
a.insertFront(“fred”);
LRS
a
Empty
_state
_state
LRS
Inserting an item into an empty LRS
a.insertFront(“fred”);
LRS
a
Empty
_state
_dat=
“fred”
_tail
NonEmpty
_state
LRS
Inserting an item into an empty LRS
a.insertFront(“fred”);
LRS
a
Empty
_state
_dat=
“fred”
_tail
NonEmpty
_state
LRS
Download