You are on page 1of 14

Objects as Classes

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

1

20 February 2012 Slide 2 .The Software to be designed  What have we got • • • • • Frame Panel Tank Alien But also… Peter Blanchfield Introduction to Software Engineering Monday.

Objects   Need to Identify Then decide classes • • • • What attributes What methods Hierarchy? Dependencies Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 3 .

maximize Peter Blanchfield Introduction to Software Engineering Monday. minimize.Objects  The Frame! • • • What has it got? Title Close. 20 February 2012 Slide 4 .

Objects  The Panel • • • • This is where things are drawn It has a way to draw itself That includes it’s background image It goes in the frame Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 5 .

Objects  These two things • • The Frame a JFrame The Panel a JPanel Imported package! import javax.swing.  Come from • • The compiler will not include anything you don’t use Peter Blanchfield Introduction to Software Engineering Monday.*. 20 February 2012 Slide 6 .

Diagram    We can diagram a class First we have a box with the name Let us start with the Frame SpaceFrame Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 7 .

20 February 2012 Slide 8 .JFrame  Our frame will be a special form of a JFrame • This is in the javax swing package import javax. JFrame  We can show that the JFrame is the general form SpaceFrame Peter Blanchfield Introduction to Software Engineering Monday.*.swing.

Panel  In the same way the Panel inherits from the JPanel JPanel AlienLandingPanel Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 9 .

The Panel is an attribute of the Frame       It is our drawing canvas It is added to the JFrame We use the add(object) method of the JFrame class We divide our class model with two lines SpaceFrame One section will hold the attributes alienLandingPanel The other the methods add(Object) Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 10 .

setName(name). Might be an SpaceFrame constructor parameter Introduction to Software Engineering Monday. 20 February 2012 Slide Peter Blanchfield 11 . • In both these cases name is a string that you have assigned the actual name to. Alternatively the parent setName method can be called super.Inheritance     The SpaceFrame will inherit from the JFrame Creating a new more special version of JFrame We can override JFrame methods Or use them direct • • • For example the JFrame constructor has a form with a title This can be called from the SpaceFrame constructor super(name).

Model Parameter SpaceFrame SpaceFrame(name:String) Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 12 .

The relationship    The AlienLandingPanel is not inherited from the SpaceFrame But they are related One AlienLandingPanel will be added to the SpaceFrame SpaceFrame AlienLandingPanel Contains Is In Peter Blanchfield Introduction to Software Engineering Monday. 20 February 2012 Slide 13 .

20 February 2012 Slide 14 .Multiplicity  This is a one to one relationship SpaceFrame AlienLandingPanel 1 Contains 1 Peter Blanchfield Introduction to Software Engineering Monday.