Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 Office Hours 10:00-11:00 am MWF 2:00-3:00 pm TTh.

Similar presentations


Presentation on theme: "CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 Office Hours 10:00-11:00 am MWF 2:00-3:00 pm TTh."— Presentation transcript:

1 CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 pargas@cs.clemson.edu Office Hours 10:00-11:00 am MWF 2:00-3:00 pm TTh

2 Overview of Course Construction and Use of Objects –Definition –Methods –Use Data Structures –Definition and Use Algorithm Analysis

3 Semester Outline 1. The Object-Oriented Method (2) 2. Comments, Conditions, and Assertions (1) 3. Vectors (3) 4. Design Fundamentals(4) 5. Sorting (2) 6.Lists(2) Test 1 7. Linear Structures (2) 9. Ordered Structures (2) 10. Trees (3) 11. Priority Queues (2) 12. Search Trees (2) 14. Graphs (1) Test 2

4 Objects Classes –templates for objects Instances or Objects –constructed from classes Message passing –usually changes state of object

5 Data Abstraction and Encapsulation Objects –sports car –string of characters –array of objects Details of structure (implementation) unimportant Interface (contract) important A p p l e 0 1 2 3 4 5 6 data

6 Object Model Data for program managed by its objects Program manipulates data through messages or method calls to the objects

7 Object-Oriented Terminology Data abstraction is accomplished through encapsulation of data in an object (an instance of a class) Fields and methods may be declared public or protected Fields are encapsulated by a class Classes are encapsulated by a package Public classes may be used by anyone who imports the package

8 Example: class Ratio Interface –public Ratio(int top, int bottom) –public int getNumerator() –public int getDenominator() –public double value() –public Ratio add(Ratio other)

9 Example: class WordList WordList, initially empty, will contain words User must be able to add words to, retrieve words from, and remove words from WordList User must know when Wordlist empty

10 Example: class WordList Interface –public WordList(int size) –public boolean isEmpty() –public void add(String s) –public String selectAny() –public void remove(String word)

11 We do not need to know anything about application other than its interaction with Object (abstract list of words) We really don’t know how WordList is implemented Result is the WordList interface Example: class WordList

12 Example: class BankAccount Read on your own Pay attention to discussion of the method equals

13 Example: Linked Lists Refer to Program #1 handout Program #1 –due Monday, August 31, 1998 –handin.102.2 1 List.java –handin.102.2 1 ListNode.java –handin.102.2 1 LinkedList.java –handin.102.2 1 *.java

14 handin.102.2 1 *.java Submission for 102 section 2 asg number 1: LinkedList.java List.java ListNode.java Do you wish to continue with the submission [y/n] y file LinkedList.java: 3642 bytes copied file List.java: 993 bytes copied file ListNode.java: 227 bytes copied handin command

15 Example: An Association Pig Latin translator Example of (key-value) pair Example of precondition Principle 2: –Free the future: reuse code

16 Interfaces Sometimes useful to describe the interface for a number of different classes without committing to an implementation No code specified in an interface Interfaces may be extended Example: public interface Store public interface Collection extends Store

17 Example: Extending Interfaces public interface Store –public int size() –public boolean isEmpty() –public void clear public interface Collection extends Store –public boolean contains(Object value) –public void add(Object value) –public Object remove(Object value) –public Iterator elements()

18 Conclusions Principle 3: Design and abide by interfaces as though you were the user Principle 4: Declare data fields protected Data abstraction is supported by separating the interface from the implementation of the data structure

19 Homework #1 Problems 1.10, 1.11, 1.13 of textbook Assigned August 26, 1998 Due September 2, 1998 Refer to printed handout distributed in class

20 Program #2 (?) Problems: 1.6, 1.7 Refer to Program #2 handout Due: September 9, 1998


Download ppt "CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 Office Hours 10:00-11:00 am MWF 2:00-3:00 pm TTh."

Similar presentations


Ads by Google