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 2 (All images from Wikimedia Commons) Object Oriented Software


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 2 (All images from Wikimedia Commons)

slide-2
SLIDE 2

Object Oriented Software Development

Question 1

How do you check equalities for the following different types? int double String

slide-3
SLIDE 3

Object Oriented Software Development

Question 1 cont...

Why shouldn’t we use == on Strings or other objects (i.e. Classes that we may make later)? Answer

slide-4
SLIDE 4

Object Oriented Software Development

Question 1 cont...

spidey1 spidey2 Implementation spidey1 == spidey2 will return false. spidey1.equals(spidey2) should return true. spidey1 == spidey1 will return true.

slide-5
SLIDE 5

Object Oriented Software Development

References

In Java, non-primitive variables are stored using references. References are similar to pointers in the sense that they store addresses to where instances are stored. They are much nicer than pointers as we don’t need manual dereferencing (&, *, ->). We may find it useful to visualize references as name tags.

slide-6
SLIDE 6

Object Oriented Software Development

Visualizing Variables

Code new Elephant();

slide-7
SLIDE 7

Object Oriented Software Development

Visualizing Variables

elph1 Code Elephant elph1 = new Elephant();

slide-8
SLIDE 8

Object Oriented Software Development

Visualizing Variables

elph1 elph2 Code Elephant elph2 = elph1;

slide-9
SLIDE 9

Object Oriented Software Development

Visualizing Variables: Mutations

elph1 elph2 Code // does elph2 change too? elph1.setFace(new HumanFace());

slide-10
SLIDE 10

Object Oriented Software Development

Visualizing Variables: Mutation = Reassignment!

elph1 elph2 Code elph2 = new Elephant();

slide-11
SLIDE 11

Object Oriented Software Development

Visualizing Variables

Recap: var = ... Assignment is like slapping name tags. On other contexts, the variable refers to whatever it is referring/pointing to.

slide-12
SLIDE 12

Object Oriented Software Development

Question 2

What is method overloading? Answer

slide-13
SLIDE 13

Object Oriented Software Development

Overloading Examples

The Good public void connect(String url) {} public void connect(IPAddress ip) {} The Bad public float max(float x, double y) { ... } public float max(double x, float y) { ... }

slide-14
SLIDE 14

Object Oriented Software Development

Java Theory

What is type casting, and describe the following types of type casting: Answer Type casting: Explicit typecasting: Implicit typecasting:

slide-15
SLIDE 15

Object Oriented Software Development

Java Theory

What is boxing and unboxing? Answer Boxing: a typecast Unboxing: a typecast

slide-16
SLIDE 16

Object Oriented Software Development

Boxing Example

Boxed variables are stored as an object, while unboxed variables are stored as a primitive data. Example int someNumber = 3; Integer boxedNumber = 3; someNumber.shortValue(); // doesn't work boxedNumber.shortValue(); // works Boxing does not have many benefits for now until we learn Generics later on.

slide-17
SLIDE 17

Object Oriented Software Development

Wrapper Classes are still useful

Most wrapper classes are useful due to their static methods. Example int number = Integer.parseInt(inputString); Notice that the most visible difference between a static and instance method is how we call them!

slide-18
SLIDE 18

Object Oriented Software Development

Design

Suppose we are developing for an uber-like start-up. How should we implement the following classes in a multi-class system? Vehicle Driver What other classes can we implement to help us implement the above classes?