Realization EEE321'07 - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Realization EEE321'07

Description:

If a method overrides a superclass method, it is not permitted to ... Remarquer le type de retour est 'Document' et non 'ascii'. Maj JW Paul. EE321.07 Winter 05 ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 31
Provided by: Kni69
Category:
Tags: eee321 | est | non | realization

less

Transcript and Presenter's Notes

Title: Realization EEE321'07


1
RealizationEEE321.07
Royal Military College of Canada Electrical and
Computer Engineering
Refs Ambler Ch 5Booch Ch 1
  • Maj JW Paul
  • Jeff.Paul_at_rmc.ca
  • 1-613-541-6000 x6656

2
There are 10 kinds of people in the world.Those
who understand binary,
and those who dont...
3
Review
  • What is Polymorphism?
  • Greek appearing in many forms
  • What is overloading?
  • meaning based on context
  • method signature
  • operators
  • What is overriding?
  • sub-type conversion

4
Overriding
  • Using a method with the same signature (which
    means?) but in a different way in a different
    class
  • The distinction is based on how the object is
    called
  • Dynamic binding (at runtime)

5
Example of Overriding
6
Polymorphism
7
An example
  • Geometric objects

square
8
Restriction in Java
  • If a method overrides a superclass method, it is
    not permitted to have a lower access level in the
    subclass than it does in the superclass JLS
    8.4.6.3

9
Parametric Polymorphism
  • Depends on type of the call parameter at the time
    of the execution of the program.
  • A very powerful feature
  • Does not exist in Java
  • C has templates

10
Power of Polymorphism
11
Polymorphic
12
Good Programming
  • Minimize access to classes and methods
  • Priority
  • Private
  • Package (aka Friendly)
  • Protected
  • Public
  • Public access should be very rare

13
Restriction in Java
  • If a method overrides a superclass method, it is
    not permitted to have a lower access level in the
    subclass than it does in the superclass JLS
    8.4.6.3

14
Abstract Classes
  • Definition

An Abstract Class can never be implemented (no
objects will be instantiated directly from this
class)
15
Abstract vs Concrete Class
  • An abstract class can have methods and attributes
  • If an abstract class has only methods, what is
    it?
  • An interface

16
Interface
  • An interface is a variation of an abstract class
  • all the methods are abstract (what does this
    mean)
  • defines only static final member variables
  • We do not inherit from interfaces, we realize
    them
  • Useful as it allows Java programmer to simulate
    multiple inheritance

17
Uses of Interfaces
  • Revealing an objects programming interface
    without revealing actual body of the class.
  • Capturing similarities between unrelated classes
    without forcing a class relationship
  • Describing "function-like" objects that can be
    passed as parameters to methods invoked on other
    objects
  • We say that the the implementation of a class is
    hidden behind the interface

18
Interface in UML
19
Interface in UML (alternate)
20
Interface in UML
21
Implementation in Java
22
Another Example
23
Inheritance vs Realization
24
Abstract Class vs Interface
  • Abstract Class
  • only instantiated by a subclass
  • may contain implemented methods
  • may contain abstract methods.
  • may contain attributes.
  • Interface
  • implemented by another class
  • may not contain implemented methods
  • may contain method signatures
  • may only contain constants (static, final)

25
Factory Method
26
Pattern Factory Method
  • Factory Method gives the responsibility of
    creating instances to the sub class
  • Use when
  • The class does not know in advace what type of
    object it must create
  • The class wants the sub-class to specify what
    type of object needs to be created
  • Allows one to decouple the product and the
    producer

27
Factory Method General Structure
Creator
Product
factoryMethod()
...
anOperation()
product factoryMethod()
...
ConcreteCreator
constructor
ConcreteProduct
...
factoryMethod()
return new ConcreteProduct
...
28
Factory Method example
create
29
Factory Method Java
Remarquer le type de retour est Document et non
ascii.
30
Good Programming
  • Use Factory Method instead of the regular
    constructor Effective Java - item 1.

31
Review
  • Why is Polymorphism Important?
Write a Comment
User Comments (0)
About PowerShow.com