Object Oriented Software Development Naufal F. Setiawan School of - - PowerPoint PPT Presentation

object oriented software development
SMART_READER_LITE
LIVE PREVIEW

Object Oriented Software Development Naufal F. Setiawan School of - - PowerPoint PPT Presentation

Object Oriented Software Development Object Oriented Software Development Naufal F. Setiawan School of Computing and Information Systems University of Melbourne Workshop 5 Object Oriented Software Development Keywords What does it mean for a


slide-1
SLIDE 1

Object Oriented Software Development

Object Oriented Software Development

Naufal F. Setiawan School of Computing and Information Systems University of Melbourne Workshop 5

slide-2
SLIDE 2

Object Oriented Software Development

Keywords

What does it mean for a variable, method, or class to be final? Answer

slide-3
SLIDE 3

Object Oriented Software Development

final

src/AssignmentUI.java /** A button to submit assignments. */ public static final Button SUBMIT_BUTTON = new Button("Submit"); public void changeButtonText(String newText) { // will this line work? SUBMIT_BUTTON.setText(newText); }

slide-4
SLIDE 4

Object Oriented Software Development

final

src/AssignmentUI.java /** A button to submit assignments. */ public static final Button SUBMIT_BUTTON = new Button("Submit"); public void changeButtonText(String newText) { // will this line work? SUBMIT_BUTTON.setText(newText); } It will! final only prevents reassignment!

slide-5
SLIDE 5

Object Oriented Software Development

Keywords

Which other classes are able to access protected members of a class? Answer

slide-6
SLIDE 6

Object Oriented Software Development

protected privacy modifier

Which other classes are able to access protected members of a class? Answer in Java: Classes in the same package will be able to access the member. Subclasses will also have access to the member (whether they are being in the same package or not.) in most languages: Only subclasses (direct and indirect) will have access to the member.

slide-7
SLIDE 7

Object Oriented Software Development

protected privacy modifier

protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in protected in

  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages
  • ther languages

protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java protected in Java

slide-8
SLIDE 8

Object Oriented Software Development

Inheritance

In terms of classes, what do we mean by inheritance? What relationship does inheritance represent? Answer

slide-9
SLIDE 9

Object Oriented Software Development

Inheritance

In terms of classes, what do we mean by inheritance? What relationship does inheritance represent? Answer Inheritance represents an “is a” relationship between a parent and child class. (Superclass and subclass.) Every (instance) attributes and methods owned by the superclass is also owned by the subclass!

slide-10
SLIDE 10

Object Oriented Software Development

Inheritance

class Instrument {} class Piano extends Instrument {} class ElectricPiano extends Piano {}

slide-11
SLIDE 11

Object Oriented Software Development

Inheritance

src/Button.java public class Button { private String text; public void onClick() { // Do something here. } }

slide-12
SLIDE 12

Object Oriented Software Development

Inheritance

src/DropdownButton.java public class DropdownButton extends Button { private ArrayList<MenuItem> items; public void onDropdownClick() { ... } }

slide-13
SLIDE 13

Object Oriented Software Development

Inheritance

The use of “parent” and “child” often causes misconceptions. Folders FolderA

FolderA1 FolderA2

FolderB FolderA1 and FolderA2 are children of FolderA (but not in the inheritance sense). They are contained inside the other. It is wrong to say “FolderA1 is a FolderA”.

slide-14
SLIDE 14

Object Oriented Software Development

Inheritance

What keyword is used to access methods and attributes of the superclass? Answer

slide-15
SLIDE 15

Object Oriented Software Development

The superconstructor

String text; void click(); String text; void click();

Item[] menuItems; void dropClick();

slide-16
SLIDE 16

Object Oriented Software Development

The superconstructor

slide-17
SLIDE 17

Object Oriented Software Development

Inheritance

What do all classes inherit from? Answer

slide-18
SLIDE 18

Object Oriented Software Development

Abstract Classes and Methods

What are abstract ... ? Answer classes: methods:

slide-19
SLIDE 19

Object Oriented Software Development

Abstract Classes

When should a class be made abstract or concrete? Answer

slide-20
SLIDE 20

Object Oriented Software Development

Abstract Classes

When should a class be made abstract or concrete? Answer It’s a design choice!

slide-21
SLIDE 21

Object Oriented Software Development

Abstract Classes

The standard guideline: make it abstract if all the subclasses make up the superclass. Suppose: Code class User { ... } class Admin extends User { ... } class Merchant extends User { ... } class Customer extends User { ... } Should we make the class User abstract?

slide-22
SLIDE 22

Object Oriented Software Development

Abstract Classes

The standard guideline: make it abstract if all the subclasses make up the superclass. Suppose: Code abstract class User { ... } class Admin extends User { ... } class Merchant extends User { ... } class Customer extends User { ... } Yes! We don’t want to instantiate any User that does not belong to any of the subclasses. Our system may not be able to handle them.

slide-23
SLIDE 23

Object Oriented Software Development

Abstract Classes

Consider the other example, now the class Window can be left as a concrete class, but why? Code class Window { ... } class TerminalWindow extends Window { ... } class BrowserWindow extends Window { ... } class EditorWindow extends Window { ... }

slide-24
SLIDE 24

Object Oriented Software Development

Polymorphism

Define what is meant by polymorphism Answer

slide-25
SLIDE 25

Object Oriented Software Development

Polymorphism

What are the four methods of polymorphism: Answer