Title: Computer Science II 810:062 Section 01
1Computer Science II810062 Section 01
2How is CS I different from CS II?
- When you teach Java there are a series of
decisions that have to be made
3How is CS I different from CS II?
- When you teach Java there are a series of
decisions that have to be made - Applet or Applications
- Core Java or Textbook package
- IDE or command line
- Object Oriented or structured
- Event-driven or Non-event driven
4How is CS I different from CS II?
- When you teach Java there are a series of
decisions that have to be made - Applet or Applications
- Core Java or Textbook package
- IDE or command line
- Object Oriented or structured
- Event-driven or Non-event driven
5How is CS I different from CS II?
- When you teach Java there are a series of
decisions that have to be made - Applet or Applications
- Core Java or Textbook package
- IDE or command line
- Object Oriented or structured
- Event-driven or Non-event driven
6How is CS I different from CS II?
- CS I focuses on learning to program in the first
place. - CS II focuses on learning how to program well
using the paradigm of Object Oriented
Programming.
7So what is OO programming?
- Object-oriented programming changes the way
software developers think about the problem by
redefining the problem. - Object-oriented programming encourages us to
think about the computer as a simulator of the
world. Thus, a program is a map of the world we
want to imitate.
8So what is OO programming?
- Instead of asking
- How can I write a program that is structured like
the machine on which it runs? - We ask
- How can I write a program that is structured like
the part of the world it describes?
9So what is OO programming?
10The anatomy of an OO program
- The world
- consists of objects
- that interact
- to solve a problem.
11So what is OO programming?
- In Java, the main thing you do is write class
definitions. (R. Morelli) - A class definition encapsulates two (three
actually) things - Data (instance variables)
- Actions (constructors and methods).
12So what is OO programming?
- But a class on its own is nearly worthless.
- The purpose of a class is to serve as a template
for creating individual objects, or instances, of
the class.
13The anatomy of an OO program
- An object is an instance of a class
- MemoPad p new MemoPad()
- While a class describes a set of objects that
behave similarly, each instance of a class is
distinct and has its own state. - MemoPad p new MemoPad()
- MemoPad q new MemoPad()
14So what is OO programming?
- an object-oriented program is a set of objects
that collaborate to achieve a goal - objects interact by sending each other messages
(invoking an objects method).
15Lets consider a MemoPad example
Allows for the storage of a collection of memos
that are associated with keys
16For example, you can insert an memo
17Identify the objects needed in the MemoPadApp
example
List the objects and their behaviors
18What came first the chicken or the egg?Since
objects create other objects dynamically as
needed, where does the first object come from?
19The anatomy of an OO program
- The world is a class that contains the main()
function. - main() is the big bang that creates one or more
objects. - public class MemoPadApp
- public static void main( String args )
MemoPad p new MemoPad()
p.show() // end main - // end class MemoPadApp
20So what is OO programming?
- Notice that main is a static method.
- We will discuss what static means in more detail
later this semester, but for now you can think of
this modifier as saying that main is associated
with the class memoPadApp, and not with any
instance of the class. - main is a class method.
21So what is OO programming?
- an object-oriented program is a set of objects
that collaborate to achieve a goal - objects interact by sending each other messages
(invoking an objects method).
22So how do objects collaborate?
- They send one another messages.
- In response to a message, an object executes the
method associated with the message that it
receives, both names and arguments. - A big part of designing an object-oriented system
is deciding what messages each object should
respond to. - The set of messages to which an object responds
is called its interface.
23Designed an interface for the memo database class
- the memo database class is used to hold the
actual memos being stored - its interface is the set of messages to which it
should respond
24Think about
- What is the behavior of a memo database?
- What should it do in order to contribute to the
world of objects that implements the behavior of
a memo pad?
25Interface for the memo database
- public interface MemoDatabase
-
- // end interface MemoDatabase
26Interface for the memo database
- public interface MemoDatabase
- public String find ( String key )
- // end interface MemoDatabase
27Interface for the memo database
- public interface MemoDatabase
- public String find ( String key )
- public boolean remove ( String key )
- public boolean insert (MemoAssociation m)
- public boolean containsKey( String key )
- // end interface MemoDatabase
28For next class
- Read chapter 1. Identify any concepts or terms
that are new to you so we can discuss them. - Re-acquaint yourself with the Java tools
available at home or in the lab. Download the
MemoPad code from the course Java page, and play
with it.