object oriented software development
play

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


  1. Object Oriented Software Development Object Oriented Software Development Naufal F. Setiawan School of Computing and Information Systems University of Melbourne Workshop 5

  2. Object Oriented Software Development Keywords What does it mean for a variable, method, or class to be final ? Answer

  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); }

  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!

  5. Object Oriented Software Development Keywords Which other classes are able to access protected members of a class? Answer

  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.

  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 other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other languages other 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

  8. Object Oriented Software Development Inheritance In terms of classes, what do we mean by inheritance? What relationship does inheritance represent? Answer

  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!

  10. Object Oriented Software Development Inheritance class Instrument {} class Piano extends Instrument {} class ElectricPiano extends Piano {}

  11. Object Oriented Software Development Inheritance src/Button.java public class Button { private String text; public void onClick() { // Do something here. } }

  12. Object Oriented Software Development Inheritance src/DropdownButton.java public class DropdownButton extends Button { private ArrayList<MenuItem> items; public void onDropdownClick() { ... } }

  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 ”.

  14. Object Oriented Software Development Inheritance What keyword is used to access methods and attributes of the superclass? Answer

  15. Object Oriented Software Development The super constructor String text; String text; void click(); void click(); Item[] menuItems; void dropClick();

  16. Object Oriented Software Development The super constructor

  17. Object Oriented Software Development Inheritance What do all classes inherit from? Answer

  18. Object Oriented Software Development Abstract Classes and Methods What are abstract ... ? Answer classes: methods:

  19. Object Oriented Software Development Abstract Classes When should a class be made abstract or concrete ? Answer

  20. Object Oriented Software Development Abstract Classes When should a class be made abstract or concrete ? Answer It’s a design choice!

  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?

  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.

  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 { ... }

  24. Object Oriented Software Development Polymorphism Define what is meant by polymorphism Answer

  25. Object Oriented Software Development Polymorphism What are the four methods of polymorphism: Answer

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend