Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementing Specifications CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides.

Similar presentations


Presentation on theme: "Implementing Specifications CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides."— Presentation transcript:

1 Implementing Specifications CpSc 372: Introduction to Software Engineering Jason O. Hallstrom jasonoh@cs.clemson.edu Authorship Disclaimer. These slides are intended to serve as teaching instruments for an undergraduate course in Software Engineering. While the slides were formatted by Dr. Hallstrom, the content is compiled from other sources, including the readings listed on the course website, Dr. Pressman’s Software Engineering textbook, and various internet materials. In almost every case, the ideas belong to someone other than Dr. Hallstrom. Indeed, text is often quoted verbatim without an explicit citation (to improve the readability of the slides). The original authors retain all copyrights. If you are interested in citing any of the material in these slides, please contact Dr. Hallstrom for the original source(s). DO NOT CITE THIS PRESENTATION. THE CONTENT SHOULD NOT BE ATTRIBUTED TO DR. HALLSTROM. SEE DR. HALLSTROM IF YOU HAVE ANY QUESTIONS.

2 CpSc 372 Interface Specifications An interface specification is a tool for describing an abstraction. An interface specification consists of four elements. A description of the abstract data model An initial value for the data model A specification says nothing about how the specification must be implemented. Hence, there can be multiple implementations of any specification. A list of exposed methods A list of method contracts

3 CpSc 372 Implementing an Interface Recall the interface specifications that we’ve discussed. public interface Set { void clear(); void add(Object x); void remove(Object x); Object removeAny(); boolean isIn(Object x); int getSize(); } public interface Sequence { void clear(); void add(int pos, Object x); Object remove(int pos); Object getElement(int pos); int getLength(); } modeled by: String of Object modeled by: Set of Object

4 CpSc 372 Representations modeled by: String of Object modeled by: Set of Object represents Consider implementing the Set interface using an implementation of the Sequence interface as the representation. (Representation = “private state”)

5 CpSc 372 Abstraction Functions <> Set of Object String of Object {}{3,1,2}{6,5} An abstraction function characterizes how an abstract model is realized by one or more concrete models. abstraction function abstract state space concrete state space

6 CpSc 372 The Code public class SetImpl1 implements Set { /* representation: self = elements(self.items) */ private Sequence items; public SetImpl1() { items = new SequenceImpl1(); } public void add(Object x) { items.add(0, x); } /* … */ public Object removeAny(x) { return(items.remove(0, x)); } /* … */ } Abstraction function

7 CpSc 372 Implementing Methods Set of Object String of Object {3,1,2} {3,1,2,0} abstract concrete s.add(new Integer(0)); this.items.add(0, x);

8 CpSc 372 Implementation Example #1 modeled by: String of Object modeled by: String of Object represents Consider implementing the Stack interface using an implementation of the Sequence interface as the representation. How would you define the abstraction function? StackSequence

9 CpSc 372 Implementation Example #1 (cont’d) String of Object abstract concrete

10 CpSc 372 Implementation Example #2 modeled by: String of Object modeled by: Pair of String of Object represents Consider implementing the Sequence interface using a pair of Stack objects as the representation. Stack (x2) Sequence

11 CpSc 372 Implementation Example #2 (cont’d) public class SequenceImpl implements Sequence { /* representation: self = ??? */ private Stack before, after; … private void moveToFront(int pos) /* requires: ??? ensures: ??? */ … } How would these be defined? How would the code be implemented?


Download ppt "Implementing Specifications CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides."

Similar presentations


Ads by Google