Abstract data types What does ‘ abstract ’ mean? From Latin: to ‘ pull out ’— the essentials –To defer or hide the details –Abstraction emphasizes essentials.

Slides:



Advertisements
Similar presentations
Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday.
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
ISBN Chapter 3 Describing Syntax and Semantics.
Inheritance Inheritance Reserved word protected Reserved word super
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
Software Engineering and Design Principles Chapter 1.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Software Testing and Quality Assurance
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Chapter 1 Principles of Programming and Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Describing Syntax and Semantics
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Programming Languages and Paradigms Object-Oriented Programming.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
© Kenneth C. Louden, Chapter 9 – Abstract Data Types and Modules Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Introduction Ellen Walker CPSC 201 Data Structures Hiram College.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Chapter 6 Use Cases. Use Cases: –Text stories Some “actor” using system to achieve a goal –Used to discover and record requirements –Serve as input to.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Two Parts of Every ADT An abstract data type (ADT)  is a type for encapsulating related data  is abstract in the sense that it hides distracting implementation.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
SWEN 5130Requirements Engineering Algebraic Specification Slide 1 Algebraic Specification u Specifying abstract types in terms of relationships between.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Introduction to Classes and Objects. Real Life When a design engineer needs an electrical motor he doesn’t need to worry about –How a foundry will cast.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
9 - Class & Method Design Model Enhancement Design to Code Proposal Presentation.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Abstract Data Types and Modules Lecture 11 – ADT and Modules, Spring CSE3302 Programming.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Laurea Triennale in Informatica – Corso di Ingegneria del Software I – A.A. 2006/2007 Andrea Polini IX. System Models (III)
Principles of Programming & Software Engineering
Data Abstraction: The Walls
Abstract Data Type.
UNIT II Queue.
Data Abstraction: The Walls
Principles of Programming and Software Engineering
About the Presentations
Introduction to Data Structures
Defining Classes and Methods
Data Structures and Algorithms for Information Processing
Defining Classes and Methods
Presentation transcript:

Abstract data types What does ‘ abstract ’ mean? From Latin: to ‘ pull out ’— the essentials –To defer or hide the details –Abstraction emphasizes essentials and defers the details, making engineering artifacts easier to use I don ’ t need a mechanic ’ s understanding of what ’ s under a car ’ s hood in order to drive it –What ’ s the car ’ s interface? –What ’ s the implementation?

Floating point numbers You don't need to know how much about floating point arithmetic works to use float –Indeed, the details can vary depending on processor, even virtual coprocessor –But the compiler hides all the details from you-- some numeric ADTs are built-in –All you need to know is the syntax and meaning of operators, +, -, *, /, etc. Hiding the details of implementation is called encapsulation (data hiding) See multimedia: ADT for digits (properties)

ADT = properties + operations An ADT describes a set of objects sharing the same properties and behaviors –The properties of an ADT are its data (representing the internal state of each object double d; -- bits representing exponent & mantissa are its data or state –The behaviors of an ADT are its operations or functions (operations on each instance) sqrt(d) / 2; //operators & functions are its behaviors Thus, an ADT couples its data and operations –OOP emphasizes data abstraction

Formal, language-independent ADTs An ADT is a formal description, not code; independent of any programming language –Why is code independence a good idea? Promotes design by contract: –Specify responsibilities of suppliers and clients explicitly, so they can be enforced, if necessary

Generic Queue ADT An ADT specification has six parts –The first three dealing with syntax … NAME, SETS and SIGNATURES NAMEQueue SETS Iset of all items (generic type) Qset of all Queues Bset of Boolean (elements T and F) Nset of natural numbers, including 0 The NAME specifies the name of a type –Generic parameter,, to specify elements of collection types SETS specifies all the types of parameters in SIGNATURES section

SIGNATURES section (see umprobso—“you are adding”) SIGNATURES Queue() -> Qfront(Q) -/-> I isEmpty(Q) -> Benqueue(Q, I) -> Q length(Q) -> Ndequeue(Q) -/-> Q SIGNATURES specifies the operations or services provided by ADT Notation of mathematical functions, with one or more inputs and producing one result: –isEmpty(Q) -> B: Given a Queue (domain), produces a Boolean (range) Functions have no side effects at all: –front(Q): given a Q, returns an item (no change) –enqueue(Q, I): returns a NEW Queue –dequeue(Q): returns another Queue Functional approach may seem inefficient, but facilitates semantics –Implementation should preserve the abstract behavior of ADT Syntax is relatively easy to specify; semantics is a bit harder ….

Full vs. partial functions SIGNATURES Queue() -> Qfront(Q) -/-> I isEmpty(Q) -> Benqueue(Q, I) -> Q length(Q) -> Ndequeue(Q) -/-> Q -> denotes a full function over the set Q, always producing the specified type of output ‑ / ‑ > denotes a partial function over the set Q, which may not always produce the output –Instead its result may be undefined When is front undefined? When is enQueue undefined? Answering these questions about partial functions is semantics Specifically, the preconditions –A partial function is undefined if any of its preconditions do not hold

Semantics of ADTs Three sections for semantics of ADTs: variables, preconditions, and postconditions VARIABLES i:I; q, r:Q; n:N; b:B PRECONDITIONS front(q) -> isEmpty (q) = false dequeue(q) -> isEmpty (q) = false VARIABLES-- declares instances of SETS, needed in PRE- and POST-CONDITIONS How are the variables used in PRECONDITIONS? What is the scope of these variables?

Preconditions Specify constraints on any partial functions, indicating when they fail front(q) -> isEmpty (q) = false //What does this constraint tell you? –PRECONDITIONs very explicit about the when a partial function fails Formalizes design by contract: analogous to written business contracts –Inspire confidence between clients and suppliers of products E.g., a contract for building a house, or a contract to write a book –A contract specifies the product that the supplier will produce –A contract also specifies the price the client will pay and other terms –Such as constraints on a contract — installments, liability, etc. ADT specifies a contract between the supplier and client of an ADT –Supplier warrants that ADT will produce the specified behavior –so long as client provides the expected inputs –so long as client doesn ’ t violate the pre-conditions, behaviors will work –if the client violates the contract (any pre-condition), the behavior fails –Yet even the failure is predictable and can be handled predictably Thus PRECONDITIONS also set up exception handling Note: no need to include trivial preconditions, e.g., isEmpty(q) -> true.

Postconditions Define effects of functions, i.e., what they accomplish POSTCONDITIONS Queue() = (qList = List()) isEmpty(q) = null(qList) length(q) = length(qList) front(q) = head(qList) enqueue(q,i) = (qList = append(qList, i)) dequeue(q,i) = (qList = tail(qList, i)) First postcondition defines constructor in terms of ListList –Reusing List implies a constructive semantics, building from other ADTs, already defined Why is constructive semantics a good fit for OOP? What does second postcondition tell you?

Axiomatic semantics Defines relations between operations strictly in terms of universal axioms (self-evident truths) –Axioms define an ADT independently of other ADTs –Constructive approach builds new ADTs based on knowledge of existing ones –The buck has to stop somewhere: e.g., the List ADT uses an axiomatic semantics –Book has an optional section on universal axioms

List postconditions (axioms) null(List()) = true //How self-evident? null(prepend(list1,i)) = null(append(list1,i)) = false //Explain? length(List()) = 0 length(append(list1, i)) = length(list1)+1 tail(append(list1,i)) = if null(list1) then [] else append(tail(list1),i))

Constructive semantics (See umprobso, “Queue of football”) Explain rest of Queue ’ s postconditions: front(q) = head(qList) enqueue(q,i) = (qList = append(qList, i)) dequeue(q,i) = (qList = tail(qList, i)) Why would this be harder with axioms? –(See umprobso, “ axiomatic ” )

Inheritance and ADTs See Employee exampleEmployee example How does inheritance affect name section? –NAME Employee SUPERTYPES Person How does inheritance affect other sections? –Employee inherits functions for name, address, etc, from Person –Inherits both syntax (SIGNATURES) and semantics –No need to redefine functions in Employee unless they do something different So Employee just supplies new constructor, GROSS_PAY, TAX_DUE –Semantics can benefit further from reuse implied by inheritance –Constructor for Employee invokes constructor for Person Could add notation {abstract} to specify abstract functions

Fruit ADT assignment Your assignment (on Blackboard): Your assignment –Improve your UML analysis Per my comments You may want to improve my analysis! –Develop an ADT design Think of it as a contract that you could hand over to a programmer (that would be you!) –Extra credit: design a user interface ADT(s) loosely coupled to problem domain ADT