200 likes | 330 Views
CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 pargas@cs.clemson.edu Office Hours 9:00-11:30 am MWF. Overview of Course. Construction and Use of Objects Definition Methods Use Data Structures Definition and Use Algorithm Analysis.
E N D
CPSC 102: Computer Science IIDr. Roy P. Pargas408 Edwards Hall864-656-5855pargas@cs.clemson.eduOffice Hours9:00-11:30 am MWF
Overview of Course • Construction and Use of Objects • Definition • Methods • Use • Data Structures • Definition and Use • Algorithm Analysis
1. The Object-Oriented Method (3) 2. Comments, Conditions, and Assertions (1) 3. Vectors (3) 4. Design Fundamentals(3) 5. Sorting (3) Test 1 6. Lists (2) 7. Linear Structures (3) 8. Iterators (2) 9. Ordered Structures (3) 10. Trees (3) Test 2 11. Priority Queues (3) 12. Search Trees (3) 13. Dictionaries (3) 14. Graphs (4) Test 3 Semester Outline
Objects • Classes • templates for objects • Instances or Objects • constructed from classes • Message passing • usually changes state of object
Data Abstraction and Encapsulation • Objects • sports car • string of characters • array of objects • Details of structure (implementation) unimportant • Interface (contract) important data A p p l e 0 1 2 3 4 5 6
Object Model • Data for program managed by its objects • Program manipulates data through messages or method calls to the objects
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
Example: class Ratio • Interface • public Ratio(int top, int bottom) • public int getNumerator() • public int getDenominator() • public double value() • public Ratio add(Ratio other)
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
Example: class WordList • Interface • public WordList(int size) • public boolean isEmpty() • public void add(String s) • public String selectAny() • public void remove(String word)
Example: class WordList • 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 WordListinterface
Example: class BankAccount • Read on your own • Pay attention to discussion of the method equals
Example: Linked Lists • Refer to Program #1 handout • Program #1 • due Monday, August 31, 1998 • handin.102.1 1 List.java • handin.102.1 1 ListNode.java • handin.102.1 1 LinkedList.java • handin.102.1 1 *.java
handin command handin.102.1 1 *.java Submission for 102 section 1 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
Example: An Association • Pig Latin translator • Example of (key-value) pair • Example of precondition • Principle 2: • Free the future:reusecode
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
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()
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
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
Program #2 (?) • Problems: 1.6, 1.7 • Refer to Program #2 handout • Due: September 9, 1998