lec02 - CSE 12 Abstraction, Classes, and Interfaces...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
02 CSE 12 Abstraction, Classes, and Interfaces Abstraction, continued ADT’s, Classes, and Interfaces The Inheritance and Composition Patterns Intro to UML Intro to the Java Collections Framework (JCF) Intro to Unit Testing with JUnit
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstraction (reviewed) A tool to manage complexity: concentrate on the interface to a “thing” – what the thing does while hiding its implementation details – how it does it Applying the concept of abstraction to data types leads to the idea of Abstract Data Types (ADT’s), which specify data values and operations while abstracting away from implementation details
Background image of page 2
Checkpoint Abstraction is useful, but. .. Are there times when it would be useful to know the implementation details of an ADT's operations or values?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstraction by interface The Application Programmer Interface (API) of List specifies everything an application programmer (client, user) needs to know in order to use a List. List insert(element) remove(element) find(element) isEmpty() public interface
Background image of page 4
Same interface, different uses Any client (user) can make use of a List through its public Application Programmer Interface (API) without knowledge of how the List is implemented.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Same interface, different implementations There are many possible implementations of any ADT. The implementation details are hidden from the user of the ADT, who can rely just on the ADT’s API.
Background image of page 6
User-defined types in Java Java has 8 primitive types : byte, short, int, long, char, float, double, boolean And those are all there are: Java does not allow additional user-defined primitive types If you want to define a type in Java, you must define either an interface , or a class Often we will use both when implementing an ADT in Java
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
01-8/25 ADT’s and Java classes An ADT specifies the possible values that instances of the ADT can have, and the operations that can be performed on them A Java class defines instance variables , and instance methods So, there is a very close relationship between an ADT and a class! Variables defined in the class correspond to ADT values Methods defined in the class correspond to ADT operations
Background image of page 8
ADT’s and Java interfaces Usually, instance variables should be private in a class They are considered part of the implementation, not to be accessed directly from outside the class Then, we write public instance methods to manipulate the instance variables Mutator methods change the values of instance variables; Accessor methods just ‘read out’ the values This permits precise control over how the instance variables can be accessed and changed So, the principle of abstraction suggests we can concentrate on the public instance methods Java interfaces do that: they define a Java type, but specify only public instance method signatures (no method bodies, no instance variables)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Software Reuse in Object-Oriented Programming You can write more software if you can make use of existing code
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2012 for the course CSE 12 taught by Professor Gary during the Fall '08 term at UCSD.

Page1 / 34

lec02 - CSE 12 Abstraction, Classes, and Interfaces...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online