Data Abstraction & Function in CMSC 433 - Programming Language Technologies - Prof. Atif M, Study notes of Programming Languages

This document from the spring 2007 semester of cmsc 433 introduces the concept of data abstraction, explaining it as the combination of objects and operations. Different categories of operations, including constructors, mutators, and observers. The abstraction function is discussed as the specification for an abstract data type's representation, and the importance of having one is emphasized. The document also covers representation invariants, their role in ensuring well-formed instances of abstract data types, and methods for implementing and checking them.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-jil
koofers-user-jil 🇺🇸

4

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 433 – Programming Language
Technologies and Paradigms
Spring 2007
Abstraction
Feb. 27, 2007
Data Abstraction
Data abstraction = objects + operations
List + { addFirst, addLast, removeFirst, ... }
Set + { add, contains, ...}
Categories of operations
Constructors (creators/producers)
Mutators/Modifiers
–Observers
Abstraction Function
Specification for data structure is abstract
Implementation of data structure is concrete
How do you know if implementation meets the
spec?
Abstraction function : concrete abstract
Specifies how the representation of an abstract data
type is interpreted as an abstract value.
Example
class IntSet { int[] elts; ... }
AF(s) = { s.elts[i] | 0 <= i <= elts.length }
You always need an abstraction function when
you build a data abstraction
Often it’s implicit
pf2

Partial preview of the text

Download Data Abstraction & Function in CMSC 433 - Programming Language Technologies - Prof. Atif M and more Study notes Programming Languages in PDF only on Docsity!

CMSC 433 – Programming Language

Technologies and Paradigms

Spring 2007

Feb. 27, 2007Abstraction

Data Abstraction

  • Set + { add, contains, ...}– List + { addFirst, addLast, removeFirst, ... }Data abstraction = objects + operations
  • Observers– Mutators/Modifiers– Constructors (creators/producers)Categories of operations

Abstraction Function

Specification for data structure is abstract

Implementation of data structure is concrete

spec?How do you know if implementation meets the

Abstraction function : concrete abstract

  • Specifies how the representation of an abstract data type is interpreted as an abstract value.

Example

class (^) IntSet (^) { int[] elts; ... (^) }

  • AF(s) = { s.elts[i] | 0 <= i <= elts.length }
  • Often it’s implicityou build a data abstractionYou always need an abstraction function when

Representation Invariant(s)

abstract data type is well formed,A constraint that characterizes whether an instance of an

  • Constraint must hold class IntSet { –^ Before and after each operation^ After the constructor has finished // rep (^) inv: elts contains (^) no duplicates int[] (^) elts; (^) ... }

Part of the (internal) specification

Implementing the Rep Invariant

public Interesting idea: Write a function to check the rep (^) boolean repOK() (^) { ...check (^) for duplicates in (^) elts... }

  • Can call during unit testing– Can add wherever you expect rep to holdWhere can you use this?

Cost?