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 Development Question 1 How do you check equalities for the following different types? int double String
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
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 .
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.
Object Oriented Software Development Visualizing Variables Code new Elephant();
Object Oriented Software Development Visualizing Variables elph1 Code Elephant elph1 = new Elephant();
Object Oriented Software Development Visualizing Variables elph1 elph2 Code Elephant elph2 = elph1;
Object Oriented Software Development Visualizing Variables: Mutations elph1 elph2 Code // does elph2 change too? elph1.setFace(new HumanFace());
Object Oriented Software Development Visualizing Variables: Mutation � = Reassignment! elph2 elph1 Code elph2 = new Elephant();
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.
Object Oriented Software Development Question 2 What is method overloading ? Answer
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) { ... }
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:
Object Oriented Software Development Java Theory What is boxing and unboxing? Answer Boxing: a typecast Unboxing: a typecast
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.
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!
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?
Recommend
More recommend