SlideShare una empresa de Scribd logo
1 de 18
cs205: engineering software
university of virginia fall 2006
Data
Abstraction
David Evans
www.cs.virginia.edu/cs205
2cs205: engineering software
Managing Complexity
• Modularity
– Divided problem into procedures
– Used specifications to separate what
from how
• A big program can have thousands of
procedures
3cs205: engineering software
Data Abstraction
• We need new data types, not just
procedures
– Could you implement PS2 without the
DirectedGraph type?
– We could make procedures, but what
would you pass to them?
• Organize program around abstract
data types
4cs205: engineering software
Abstract Data Types
• Separate what you can do with data
from how it is represented
• Client interacts with data through
provided operations according to
their specifications
• Implementation chooses how to
represent data and implement its
operations
5cs205: engineering software
Data Abstraction in Java
• A class defines a new data type
• Use private instance variables to
hide the choice of representation
– private declarations are only visible
inside the class
6cs205: engineering software
Up and Down
Abstract Type
Concrete Representation
class implementation
clients
down
upThe representation of an abstract data type
is visible only in the class implementation.
Clients manipulate an abstract data type by
calling its operations (methods and constructors)
7cs205: engineering software
Example: CellState
public class CellState {
// OVERVIEW: A CellState is an immutable
// object that represents the state of a cell,
// either alive or dead.
static public CellState createAlive()
// EFFECTS: Returns an alive cell state.
static public CellState createDead ()
// EFFECTS: Returns a dead cell state.
public boolean isAlive ()
// EFFECTS: Returns true iff this is alive.
}
8cs205: engineering software
Cell State Representation
private boolean alive;
public boolean isAlive () { return alive; }
Abstract Type
Concrete Representation
class implementation
clients
down
up
CellState cs.isAlive ()
9cs205: engineering software
Advantages/Disadvantages
- More code to write and maintain
- Run-time overhead (time to call
method)
+ Client doesn’t need to know about
representation
+ Suppose we want to add more states
(e.g., question 2)
10cs205: engineering software
Set Example (ps2)
• Set abstract data type: represent a
set of objects
• Operations:
– Create an empty set
– Mathematical set operations: add,
contains, size, remove, union
11cs205: engineering software
Type Parameters
• We want to have sets of different
types of objects
• How should we declare the Set
methods?
public boolean add(?? elem)
public boolean contains(?? elem)
public ?? choose()
We don’t want just one Set datatype.
We want different Sets for different element types.
12cs205: engineering software
Generic Datatype
public class Set<T> {
...
public boolean add(T el)
public T choose()
public boolean contains(T el)
...
} Note: Java did not support generic
datatypes until version 1.5 (this is why
the book doesn’t use them)
13cs205: engineering software
Creating Specific Types
public class Set<T> {
...
public boolean add(T el)
public T choose()
public boolean contains(T el)
...
}
public class Set<String> {
...
public boolean add(String el)
public String choose()
public boolean contains(String el)
...
}
Set<String>
14cs205: engineering software
Abstract Data Type Specifications
• Overview: what the type represents
– Mutability/Immutability
A Set is a mutable, unbounded set of objects
of type T.
– Abstract Notation
A typical Set is { x1, …, xn }.
• Operations: procedural specifications
for each operation (public methods and
constructors); use the abstract
notation introduced in overview.
15cs205: engineering software
Set Specification
public class Set<T> implements Iterable<T>, Collection<T> {
OVERVIEW: A Set is a mutable, unbounded set of objects of
type T. A typical Set is {x_1, ..., x_n }.
public Set()
EFFECTS: Initializes this to an empty set: { }.
public boolean add(T el)
MODIFIES: this
EFFECTS: Adds el to the elements of this:
thispost = thispre U { el }
Returns true iff el was not an element of thispre.
16cs205: engineering software
Components of Data Abstractions
• Ways to create objects of the data type
– Creators: create new objects of the ADT
from parameters of other types
– Producers: create new objects of the ADT
from parameters of the ADT type (and
other types)
• Ways to observe properties: observers
• Ways to change properties: mutators
17cs205: engineering software
Set Operations
public class Set<T> implements Iterable<T>, Collection<T> {
OVERVIEW: A Set is a mutable, unbounded set of objects of
type T. A typical Set is {x_1, ..., x_n }.
public Set()
EFFECTS: Initializes this to an empty set: { }.
public Set(Set<T> s)
EFFECTS: Initializes this to a set containing the
same elements as the set s (a shallow copy).
public boolean add(T el)
MODIFIES: this
EFFECTS: Adds el to the elements of this:
this_post = this_pre U { el }
Returns true iff el was not an element of this_pre.
public void union(Set<T> t)
MODIFIES: this
EFFECTS: this_post = this_pre U t
public T choose()
REQUIRES: this has at least one element
EFFECTS: Returns an element of this.
public boolean contains(Object el)
EFFECTS: Returns true iff el is an element of this.
public int size()
EFFECTS: Returns the number of elements in this.
public boolean isEmpty()
EFFECTS: Returns true iff this has no elements.
public boolean remove(Object el)
MODIFIES: this
EFFECTS: Removes el from this:
this_post = this_pre - { el }
Returns true iff el is in this_pre
18cs205: engineering software
PS2
• Several datatype implementations provided
with specifications
• Client interacts with data type using the
methods as described in the specification
• Client does not know the concrete
representation
• Your code should work correctly with any
correct implementation of the specified
datatype

Más contenido relacionado

La actualidad más candente

04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructorHaresh Jaiswal
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3Mahmoud Ouf
 
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...Giyeon Bang
 
Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...licservernoida
 
Linear Regression Parameters
Linear Regression ParametersLinear Regression Parameters
Linear Regression Parameterscamposer
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS ResponsibilitiesBrendan Eich
 
Mind the Gap - Data Science Meets Software Engineering
Mind the Gap - Data Science Meets Software EngineeringMind the Gap - Data Science Meets Software Engineering
Mind the Gap - Data Science Meets Software EngineeringBernhard Haslhofer
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sortingheshekik
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8Berk Soysal
 
Insertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority QueuesInsertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority QueuesPriyanka Rana
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to VectorsRsquared Academy
 
Teach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with ScalaTeach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with ScalaDamian Jureczko
 
CS-141 Java programming II ASSIGNMENT 2
CS-141 Java programming II ASSIGNMENT 2CS-141 Java programming II ASSIGNMENT 2
CS-141 Java programming II ASSIGNMENT 2Voffelarin
 

La actualidad más candente (20)

04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
 
Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...
 
Linear Regression Parameters
Linear Regression ParametersLinear Regression Parameters
Linear Regression Parameters
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
 
Mind the Gap - Data Science Meets Software Engineering
Mind the Gap - Data Science Meets Software EngineeringMind the Gap - Data Science Meets Software Engineering
Mind the Gap - Data Science Meets Software Engineering
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sorting
 
Queue
QueueQueue
Queue
 
Sorting
SortingSorting
Sorting
 
123
123123
123
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
 
Insertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority QueuesInsertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority Queues
 
Link List
Link ListLink List
Link List
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Teach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with ScalaTeach Yourself some Functional Programming with Scala
Teach Yourself some Functional Programming with Scala
 
CS-141 Java programming II ASSIGNMENT 2
CS-141 Java programming II ASSIGNMENT 2CS-141 Java programming II ASSIGNMENT 2
CS-141 Java programming II ASSIGNMENT 2
 
Chap08
Chap08Chap08
Chap08
 

Destacado (8)

Lecture6
Lecture6Lecture6
Lecture6
 
Sockets
SocketsSockets
Sockets
 
1
11
1
 
Lecture5 2
Lecture5 2Lecture5 2
Lecture5 2
 
Tcp
TcpTcp
Tcp
 
Rd
RdRd
Rd
 
Amcat+syllabus+and+sample+papers
Amcat+syllabus+and+sample+papersAmcat+syllabus+and+sample+papers
Amcat+syllabus+and+sample+papers
 
Amcat placement questions
Amcat placement questionsAmcat placement questions
Amcat placement questions
 

Similar a Lecture7

A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiDatabricks
 
6.SE_Requirements Modeling.ppt
6.SE_Requirements Modeling.ppt6.SE_Requirements Modeling.ppt
6.SE_Requirements Modeling.pptHaiderAli252366
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overviewpradeepkothiyal
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxCertification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxRohit Radhakrishnan
 
SQL Saturday 28 - .NET Fundamentals
SQL Saturday 28 - .NET FundamentalsSQL Saturday 28 - .NET Fundamentals
SQL Saturday 28 - .NET Fundamentalsmikehuguet
 
Spark Summit EU talk by Herman van Hovell
Spark Summit EU talk by Herman van HovellSpark Summit EU talk by Herman van Hovell
Spark Summit EU talk by Herman van HovellSpark Summit
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.pptYonas D. Ebren
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
Project Management System
Project Management SystemProject Management System
Project Management SystemDivyen Patel
 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfjorgeulises3
 

Similar a Lecture7 (20)

00-review.ppt
00-review.ppt00-review.ppt
00-review.ppt
 
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
 
Intake 37 linq3
Intake 37 linq3Intake 37 linq3
Intake 37 linq3
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
L04 Software Design Examples
L04 Software Design ExamplesL04 Software Design Examples
L04 Software Design Examples
 
6.SE_Requirements Modeling.ppt
6.SE_Requirements Modeling.ppt6.SE_Requirements Modeling.ppt
6.SE_Requirements Modeling.ppt
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overview
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxCertification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptx
 
SQL Saturday 28 - .NET Fundamentals
SQL Saturday 28 - .NET FundamentalsSQL Saturday 28 - .NET Fundamentals
SQL Saturday 28 - .NET Fundamentals
 
Spark Summit EU talk by Herman van Hovell
Spark Summit EU talk by Herman van HovellSpark Summit EU talk by Herman van Hovell
Spark Summit EU talk by Herman van Hovell
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
Lec1
Lec1Lec1
Lec1
 
algo 1.ppt
algo 1.pptalgo 1.ppt
algo 1.ppt
 
Project Management System
Project Management SystemProject Management System
Project Management System
 
F sharp - an overview
F sharp - an overviewF sharp - an overview
F sharp - an overview
 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Lecture7

  • 1. cs205: engineering software university of virginia fall 2006 Data Abstraction David Evans www.cs.virginia.edu/cs205
  • 2. 2cs205: engineering software Managing Complexity • Modularity – Divided problem into procedures – Used specifications to separate what from how • A big program can have thousands of procedures
  • 3. 3cs205: engineering software Data Abstraction • We need new data types, not just procedures – Could you implement PS2 without the DirectedGraph type? – We could make procedures, but what would you pass to them? • Organize program around abstract data types
  • 4. 4cs205: engineering software Abstract Data Types • Separate what you can do with data from how it is represented • Client interacts with data through provided operations according to their specifications • Implementation chooses how to represent data and implement its operations
  • 5. 5cs205: engineering software Data Abstraction in Java • A class defines a new data type • Use private instance variables to hide the choice of representation – private declarations are only visible inside the class
  • 6. 6cs205: engineering software Up and Down Abstract Type Concrete Representation class implementation clients down upThe representation of an abstract data type is visible only in the class implementation. Clients manipulate an abstract data type by calling its operations (methods and constructors)
  • 7. 7cs205: engineering software Example: CellState public class CellState { // OVERVIEW: A CellState is an immutable // object that represents the state of a cell, // either alive or dead. static public CellState createAlive() // EFFECTS: Returns an alive cell state. static public CellState createDead () // EFFECTS: Returns a dead cell state. public boolean isAlive () // EFFECTS: Returns true iff this is alive. }
  • 8. 8cs205: engineering software Cell State Representation private boolean alive; public boolean isAlive () { return alive; } Abstract Type Concrete Representation class implementation clients down up CellState cs.isAlive ()
  • 9. 9cs205: engineering software Advantages/Disadvantages - More code to write and maintain - Run-time overhead (time to call method) + Client doesn’t need to know about representation + Suppose we want to add more states (e.g., question 2)
  • 10. 10cs205: engineering software Set Example (ps2) • Set abstract data type: represent a set of objects • Operations: – Create an empty set – Mathematical set operations: add, contains, size, remove, union
  • 11. 11cs205: engineering software Type Parameters • We want to have sets of different types of objects • How should we declare the Set methods? public boolean add(?? elem) public boolean contains(?? elem) public ?? choose() We don’t want just one Set datatype. We want different Sets for different element types.
  • 12. 12cs205: engineering software Generic Datatype public class Set<T> { ... public boolean add(T el) public T choose() public boolean contains(T el) ... } Note: Java did not support generic datatypes until version 1.5 (this is why the book doesn’t use them)
  • 13. 13cs205: engineering software Creating Specific Types public class Set<T> { ... public boolean add(T el) public T choose() public boolean contains(T el) ... } public class Set<String> { ... public boolean add(String el) public String choose() public boolean contains(String el) ... } Set<String>
  • 14. 14cs205: engineering software Abstract Data Type Specifications • Overview: what the type represents – Mutability/Immutability A Set is a mutable, unbounded set of objects of type T. – Abstract Notation A typical Set is { x1, …, xn }. • Operations: procedural specifications for each operation (public methods and constructors); use the abstract notation introduced in overview.
  • 15. 15cs205: engineering software Set Specification public class Set<T> implements Iterable<T>, Collection<T> { OVERVIEW: A Set is a mutable, unbounded set of objects of type T. A typical Set is {x_1, ..., x_n }. public Set() EFFECTS: Initializes this to an empty set: { }. public boolean add(T el) MODIFIES: this EFFECTS: Adds el to the elements of this: thispost = thispre U { el } Returns true iff el was not an element of thispre.
  • 16. 16cs205: engineering software Components of Data Abstractions • Ways to create objects of the data type – Creators: create new objects of the ADT from parameters of other types – Producers: create new objects of the ADT from parameters of the ADT type (and other types) • Ways to observe properties: observers • Ways to change properties: mutators
  • 17. 17cs205: engineering software Set Operations public class Set<T> implements Iterable<T>, Collection<T> { OVERVIEW: A Set is a mutable, unbounded set of objects of type T. A typical Set is {x_1, ..., x_n }. public Set() EFFECTS: Initializes this to an empty set: { }. public Set(Set<T> s) EFFECTS: Initializes this to a set containing the same elements as the set s (a shallow copy). public boolean add(T el) MODIFIES: this EFFECTS: Adds el to the elements of this: this_post = this_pre U { el } Returns true iff el was not an element of this_pre. public void union(Set<T> t) MODIFIES: this EFFECTS: this_post = this_pre U t public T choose() REQUIRES: this has at least one element EFFECTS: Returns an element of this. public boolean contains(Object el) EFFECTS: Returns true iff el is an element of this. public int size() EFFECTS: Returns the number of elements in this. public boolean isEmpty() EFFECTS: Returns true iff this has no elements. public boolean remove(Object el) MODIFIES: this EFFECTS: Removes el from this: this_post = this_pre - { el } Returns true iff el is in this_pre
  • 18. 18cs205: engineering software PS2 • Several datatype implementations provided with specifications • Client interacts with data type using the methods as described in the specification • Client does not know the concrete representation • Your code should work correctly with any correct implementation of the specified datatype