Computer Science II 810:062 Section 01 - PowerPoint PPT Presentation

About This Presentation
Title:

Computer Science II 810:062 Section 01

Description:

Computer Science II. 810:062 Section 01. How is CS I different from CS II? ... 'In Java, the main thing you do is write class definitions.' ( R. Morelli) ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 29
Provided by: markf91
Learn more at: http://www.cs.uni.edu
Category:

less

Transcript and Presenter's Notes

Title: Computer Science II 810:062 Section 01


1
Computer Science II810062 Section 01
2
How is CS I different from CS II?
  • When you teach Java there are a series of
    decisions that have to be made

3
How 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

4
How 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

5
How 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

6
How 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.

7
So 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.

8
So 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?

9
So what is OO programming?
10
The anatomy of an OO program
  • The world
  • consists of objects
  • that interact
  • to solve a problem.

11
So 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).

12
So 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.

13
The 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()

14
So 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).

15
Lets consider a MemoPad example
Allows for the storage of a collection of memos
that are associated with keys
16
For example, you can insert an memo
17
Identify the objects needed in the MemoPadApp
example
List the objects and their behaviors
18
What came first the chicken or the egg?Since
objects create other objects dynamically as
needed, where does the first object come from?
19
The 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

20
So 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.

21
So 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).

22
So 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.

23
Designed 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

24
Think 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?

25
Interface for the memo database
  • public interface MemoDatabase
  • // end interface MemoDatabase

26
Interface for the memo database
  • public interface MemoDatabase
  • public String find ( String key )
  • // end interface MemoDatabase

27
Interface 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

28
For 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.
Write a Comment
User Comments (0)
About PowerShow.com