Abstraction, Functions, and Representation Invariants

Abstraction, Functions, and Representation Invariants
Slide Note
Embed
Share

Dive into the concepts of data abstraction, representation states, and the importance of abstraction functions. Explore the key notions of state and motivation behind hiding implementations from clients. Understand the role of abstraction functions in mapping states and the significance of representation invariants in capturing implementation constraints.

  • Abstraction
  • Functions
  • Representation
  • Invariants
  • Java

Uploaded on Apr 12, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Abstraction Functions and Representation Invariants Paul Ammann

  2. Data Abstraction Abstract State (Client State) Representation State (Internal State) Methods (behavior) Constructors (create objects) Producers (return immutable object) Mutators (change state) Observers (report about state) This lecture is about state only 2

  3. What is State? Key notion Definition: A state is an assignment of values to variables. Need to consider all possible values for each variable State space is cross product of possible values for each individual variable Java example: Variables: List list; int x; Possible States: list = [], x = 5 list = null; x = 0 list = [ cat , dog ]; x = -8 list = [ cat , 1, null]; x = 0 etc. 3

  4. Motivation Why hide implementation from client? Makes reimplementation (maintenance) possible! Protects implementation from client Lecture covers two key notions Abstraction function Implemented by toString() in Java Representation Invariant Not standard in Java, but fits assertion mechanisms Is available in C# (VisualStudio Code Contracts) 4

  5. Abstraction Function Abstract state What the client sees Examples given in class Representation state What the implementation manipulates Examples given in class Abstraction function simply maps representation states to abstract states Required for any implementation Difference here we re documenting it! Code examples: in-class exercises 5

  6. Rep Invariant Rep invariant captures constraints on implementation variables Why my code works English descriptions are fine But needs to be coded to be effective Can check in Junit tests Code examples: in-class exercises 6

More Related Content