Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Class Hierarchies. Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. An.
Inheritance Inheritance Reserved word protected Reserved word super
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 10: Inheritance and Polymorphism
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
LECTURE 07 Programming using C# Inheritance
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Java Applets and other things. Applets Very like usual classes Use init() method instead of main Applets provide 4 methods init() start() stop() destroy()
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
CMSC 202 Polymorphism. 10/20102 Topics Binding (early and late) Upcasting and downcasting Extensibility The final modifier with  methods  classes.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Inheritance ndex.html ndex.htmland “Java.
CH10 Supplementary Material Prepared by Fatimah Alakeel Oct 2010.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Polymorphism Lecture - 9.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
BY:- TOPS Technologies
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Polymorphism in Methods
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
Final and Abstract Classes
Inheritance and Polymorphism
Java Programming Language
Inheritance, Polymorphism, and Interfaces. Oh My
CS18000: Problem Solving and Object-Oriented Programming
Java – Inheritance.
Java Inheritance.
Advanced ProgramMING Practices
Chapter 9 Carrano Chapter 10 Small Java
Inheritance and Polymorphism
Advanced ProgramMING Practices
Chapter 11 Inheritance and Polymorphism Part 1
Final and Abstract Classes
Chapter 11 Inheritance and Encapsulation and Polymorphism
Presentation transcript:

Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)

Inheritance  allows a class to use the properties and methods of another class while adding its own functionality  for example:  you could create a generic student class with states and actions that are common to all students  parent, aka, superclass, base class  then, more specific classes could be created for part-time, fulltime, and continuing students  children, aka, subclasses, derived classes  enhances the ability to reuse code  makes design a much simpler and cleaner 2 This slide is based on: ReferencesReferences

Inheritance  the Object class is the highest superclass of Java  all other classes are subclasses inheriting from it  we use the extends keyword to set the relationship between a superclass and a subclass  you can override methods, that is to create a new set of method statements for the same method signature  method signature includes the name, the number of parameters, and the parameter types  you cannot override final methods, methods in final classes, and private or static methods 3 This slide is based on: ReferencesReferences

Inheritance  when extending a class constructor you can reuse the superclass constructor and overridden superclass methods by using the reserved word super  this reference must come first in the subclass constructor  the reserved word this is used to distinguish between the object's property and the passed in parameter  could be used to reference private constructors as well  beneficial for initializing properties 4 This slide is based on: ReferencesReferences

Inheritance – Superclass public class Animal { public void sleep() { System.out.println("Sleeping"); } public void walk() { System.out.println("Walking"); } public void eat() { System.out.println("Eating"); } 5 This slide is based on: ReferencesReferences

Inheritance – Subclasses public class Dog extends Animal { public void bark() { System.out.println("Woof!"); } public class Cat extends Animal { public void meow() { System.out.println("Meow!"); } Dog myDog = new Dog(); myDog.eat(); 6 This slide is based on: ReferencesReferences

Abstract  a superclass is more general than its subclasses and contains elements and properties common to all of the subclasses  a superclass could be set up as an abstract class  does not allow objects of its prototype to be created  only objects of the subclass are used  forcing the client to create specific animals like a Cat or a Dog 7 This slide is based on: ReferencesReferences

Abstract – Superclass public abstract class Animal { public void sleep() { System.out.println("Sleeping"); } public void walk() { System.out.println("Walking"); } public void eat() { System.out.println("Eating"); } Animal myAnimal = new myAnimal(); 8 X This slide is based on: ReferencesReferences

Abstract Methods  abstract methods are methods with no body specification  you create a method but do not fill in the code inside of it  subclasses must provide the method statements for their particular meaning  would require overriding in each subclass, the applied method statements may be inappropriate otherwise 9 This slide is based on: ReferencesReferences

Abstract Method in Superclass public abstract class Animal { public void sleep() { System.out.println("Sleeping"); } public void walk() { System.out.println("Walking"); } public void eat() { System.out.println("Eating"); } public abstract void speak(); } 10 This slide is based on: ReferencesReferences

Abstract Methods – Subclasses public class Dog extends Animal { public void speak() { System.out.println("Woof!"); } public class Cat extends Animal { public void speak() { System.out.println("Meow!"); } 11 This slide is based on: ReferencesReferences

Interfaces  similar to abstract classes but all methods are abstract and all properties are static final  interfaces can be inherited  you can have a sub-interface  the extends keyword is used for inheritance  You cannot have multiple inheritance for classes, hence, an interface is used to tie elements of several classes together  used to separate design from coding as class method headers are specified but not their bodies  allows compilation and parameter consistency testing prior to the coding phase  used to set up unit testing frameworks 12 This slide is based on: ReferencesReferences

Interfaces – Superclass and Dog public interface Talking { public void work(); }  subclass Dog public class Dog extends Animal implements {... public void work() { speak(); System.out.println("Be aware of me!!"); } 13 This slide is based on: ReferencesReferences

Polymorphism  allows an action or method to do different things based on the object that it is acting upon  three types of polymorphism 1. overloading 2. overriding 3. late (or dynamic) method binding 14 This slide is based on: ReferencesReferences

Overloaded and Overridden Methods  overloaded methods with the same name signature but either a different number of parameters or different types in the parameter list  overridden methods are redefined within an inherited or a subclass and have the same signature and the subclass definition is used 15 This slide is based on: ReferencesReferences

Late Method Binding  it allows a program to resolve references to subclass methods at runtime  for instance, let’s assume  we have two subclasses Dog and Cat that are created based on the Animal abstract class  they both have their own speak() method  in that case, although each method reference is to an Animal, the code will resolve the correct method reference at runtime 16 This slide is based on: ReferencesReferences

Late Method Binding  client code public class AnimalReference { public static void main(String args[]) { Animal myDog = new Dog("Scooby Doo"); Cat myCat = new Cat("Garfield"); // now reference each as an Animal myDog.speak(); myCat.speak(); } output for myDog.speak() Woof! Be aware of me!! 17 This slide is based on: ReferencesReferences

Model-View-Controller (MVC)  the Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes [Burbeck92] 18 This slide is based on: ReferencesReferences

Model-View-Controller (MVC)  model – manages the behaviour and data of the application domain  responds to requests for information about its state  usually from the view, and  responds to instructions to change state  usually from the controller  view – manages the display of information  controller – interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate in Web applications view is the browser and controller is the server-side components handling the HTTP request 19 This slide is based on: ReferencesReferences

Model-View-Controller (MVC)  both the view and the controller depend on the model  the model depends on neither  this separation allows the model to be built and tested independent of the visual presentation  however, view and controller is sometimes implemented as one object in UI 20 This slide is based on: ReferencesReferences

Model-View-Controller (MVC) once the MVC objects are instantiated:  the view registers as a listener on the model  any changes to the underlying data of the model immediately cause a broadcast change notification that the view receives  the controller is bound to the view  any user actions that are performed on the view will invoke a registered listener method in the controller class  the controller is given a reference to the underlying model 21 This slide is based on: ReferencesReferences

Model-View-Controller (MVC)  when a user interacts with the view:  the view recognizes that a GUI action, i.e. dragging a scroll bar, etc. has occurred, using a listener method that is registered to be called when such an action occurs  the view calls the appropriate method on the controller  the controller accesses the model, possibly updating it in a way appropriate to the user's action.  if the model has been altered, it notifies interested listeners, such as the view, of the change 22 This slide is based on: ReferencesReferences

Model-View-Controller (MVC) 23 This slide is based on: ReferencesReferences

Model-View-Controller (MVC) 24 This slide is based on: ReferencesReferences

 inheritance, abstract, interfaces, and polymorphism  John W. M. Russell’s Notes John W. M. Russell’s Notes  Java Made Easy Java Made Easy  The Java TM Tutorial The Java TM Tutorial  MVC  The Java TM Tutorial The Java TM Tutorial  Web Presentation Patterns Web Presentation Patterns  Java SE Application Design With MVC Java SE Application Design With MVC 25

Writtentest  similar to writtentest #1 and writtentest #2  10 true/false= 10 marks  10 short questions= 10 marks  explanations/procedures = marks  methods, etc.= marks  total = marks 26

Labtest  will be combination of several topics that we have discussed:  GUI X recursion  linked lists/arrays X recursion  linked lists/arrays X GUI  etc.  practice:  PExs  exercises from the recommended book  examples from the lecture notes and the slides 27