Introduction to Database Development
Download
Report
Transcript Introduction to Database Development
M1G413283
Introduction to
Programming 2
1. Designing a program
Teaching staff
Jim Paterson
Room M628
[email protected]
Katrin Hartmann
Room 611
Introduction to Programming 2
1. Designing a program
2
Online resources
Blackboard
Announcements
Assessment information
Course website
Can be accessed through Blackboard
www.paterson.co.uk/gcal/intro2prog2.shtml
Lecture notes, lab & tutorial sheets, etc
Links to other resources
Introduction to Programming 2
1. Designing a program
3
Reading
No set text – notes will be provided
The following books are recommended as
additional reading:
Objects First with Java: A Practical Introduction
Using BlueJ by David J. Barnes and Michael
Kolling (ISBN 0137005628)
Studying Programming by Sally Fincher (ISBN
1403946876)
Introduction to Programming 2
1. Designing a program
4
Assessment
Class test
Lab exercises
PeerWise
Introduction to Programming 2
1. Designing a program
5
Models in software development
A software system can be modelled using, for
example, class diagrams
A model of the data in the system can be
used to help design a database
A model can also be used to help design and
create the software application, or program,
which actually carries out the functions of the
system
Introduction to Programming 2
1. Designing a program
6
Java programs
A Java program can be:
A few lines of code which perform a single
function, for example to add two numbers
A large enterprise system consisting of many
Java classes which provide very complex services
Anything in between...
Introduction to Programming 2
1. Designing a program
7
Java programs
User interface can be:
Windows application
Web pages
Web page applets
Phone applications
Games
Embedded
Command line
etc...
Introduction to Programming 2
1. Designing a program
8
Object-oriented programs
Java is an object-oriented programming
language
When an object-oriented program is running,
it creates objects which work together, or
collaborate, to perform the required actions
These objects often represent entities in the
system
GCU Tours system has objects representing
customers, bookings, and so on
Introduction to Programming 2
1. Designing a program
9
Classes and objects
An OO program creates objects as it runs
Nees to have a template which specifies
what type of object will be created and what
that type of object can do
This template is called a class
In fact, when you write a program, you are
actually writing the templates
An object is a single instance of a class –
there can be many objects of the same type
Introduction to Programming 2
1. Designing a program
10
Class contents
A class specifies the following for the objects
it is used to create:
The name of the type of object (e.g. Customer)
The properties which each object will have (e.g.
name)
The actions which each object can perform (e.g.
change password)
The way in which each object is linked with
other objects (e.g. with Booking objects)
Introduction to Programming 2
1. Designing a program
11
Other languages
Other popular object-oriented languages
include C#, Visual Basic.NET, C++, Python
In your university career you will come across
a number of languages
Many of the techniques which you learn with
Java have equivalents in other languages
Once you learn Java it is relatively easy to
adapt to others.
Introduction to Programming 2
1. Designing a program
12
What do classes represent?
Information
May be information which needs to be stored
permanently - database
User
-name
-address
-username
-password
-datejoined
Booking
1..1
0..*
-adults
-children
-bookingdate
-status
0..*
1..1
Package
-location
-name
-description
-adultprice
-childprice
-departure
Tour
-departuredate
-offer
1..1
0..*
Introduction to Programming 2
1. Designing a program
13
What do classes represent
Not all classes represent information
Other roles for classes:
Getting input from the user and displaying output
Controlling the flow of activity while the program
runs
Other specialised tasks for example formatting
output, getting information into and out of the
database, and so on
Introduction to Programming 2
1. Designing a program
14
The GCU Adventure Game
Simple example of a system which uses
objects which do a range of jobs and work
together as a complete program
The GCU game is a text adventure game
(interactive fiction)
Inspired by Hitchhikers’ Guide to the Galaxy
game (but not as exciting!)
Borrowed liberally from example in Barnes
and Kolling book
Introduction to Programming 2
1. Designing a program
15
Description of the game
The game centres around characters
travelling through a world which consists of
rooms
Each room has a description
Rooms have exits which lead to other rooms
Each room can contain several items which
may be used by a character when in that
room
Introduction to Programming 2
1. Designing a program
16
Description of the game
An item will also have a description
A player navigates through a world by typing
commands (go north, go south, quit, and so
on)
The game can be played by several players
Introduction to Programming 2
1. Designing a program
17
Objects in the game
game – this will be an object which sets up
the game world and controls the game play
room – this will be an object which
represents a room in the game world
There will be only one Game object
There may be many rooms.
item – this will be an object which represents
an item in a room
There may be several items in each room.
Introduction to Programming 2
1. Designing a program
18
Objects in the game
description – this simply describes a room
or item
exit – an exit from a room is really just a way
into another room
a property rather than an object in its own right
exit is actually a way of referring to a room
object
player – this will be an object which
represents a player
player will be in one room at any time
Introduction to Programming 2
1. Designing a program
19
Objects in the game
There may be several players in the game.
command – this will be an object as the job
of representing players’ actions may be quite
complicated
Each player should have a name, which is a
property of the object.
one command object for each input entered by
a player.
Others may be required as program develops
Introduction to Programming 2
1. Designing a program
20
Model for the game
Class diagram shows classes and properties
identified, and suggests how they may be
linked, or associated
Game
Command
Room
-description
Player
-exit
-name
Item
-description
Introduction to Programming 2
1. Designing a program
21
Importance of the class diagram
While it is usually not the only part of a model
of a system, the class diagram is very
important when you start to build the system
as a Java program
The classes become the Java classes which
you need to write
Other diagrams are also useful, e.g. Activity,
use case, sequence
Introduction to Programming 2
1. Designing a program
22
What’s next?
Build incrementally a working implementation
of the “World of GCU” adventure game
As we do so you will learn about some new
programming techniques and tools as they
are needed
You will also learn how the associations
between classes in the game are
implemented in Java
Introduction to Programming 2
1. Designing a program
23