exercise session 6
play

Exercise Session 6 Andrei Vancea Todays Exercise Session - PowerPoint PPT Presentation

Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Exercise Session 6 Andrei Vancea Todays Exercise Session Assignment VI Hints Questions Pattern of the Day The Abstract Factory


  1. Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Exercise Session 6 Andrei Vancea

  2. Today’s Exercise Session Assignment VI  Hints  Questions Pattern of the Day  The Abstract Factory Quizzes Languages in Depth series: Java Programming 2

  3. Assignment V Hints Questions Languages in Depth series: Java Programming 3

  4. Abstract Factory Creational Pattern  Concerned with object creation Provide an interface for creating families of related or dependent objects without specifying their concrete classes. AKA : Kit Languages in Depth series: Java Programming 4

  5. Abstract Factory - Structure AbstractFactory  Declares an interface for operations that create abstract product objects. ConcreteFactory  Implements the operations to create concrete product objects. Languages in Depth series: Java Programming 5

  6. Abstract Factory - structure AbstractProduct  Declares an interface for a type of product object. ConcreteProduct  Defines a product object to be created by the corresponding concrete factory.  Implements the AbstractProduct interface. Client  uses only interfaces declared by AbstractFactory and AbstractProduct classes. Languages in Depth series: Java Programming 6

  7. Abstract Factory – Example * Languages in Depth series: Java Programming *from http://en.wikipedia.org/wiki/Abstract_factory_pattern 7

  8. Abstract Factory – Example Languages in Depth series: Java Programming 8

  9. Abstract Factory – Consequences It isolates concrete classes.  Clients manipulate instances through their abstract interfaces.  Product class names are isolated in the implementation of the concrete factory. It makes exchanging product families easy.  Easy to change the concrete factory an application uses.  Because an abstract factory creates a complete family of products, the whole product family changes at once (Ex : change GUI from Windows to Mac). Supporting new kinds of products is difficult  AbstractFactory interface fixes the set of products.  A new product requires changing the AbstractFactory and all of its subclasses Languages in Depth series: Java Programming 9

  10. What Does It Print? Exception java.lang.StackOver flowError Languages in Depth series: Java Programming 10

  11. What Does It Print? Instance variable initializers run before the body of the constructor The initializer for the variable internalInstance invokes the constructor recursively. These recursive invocations cause a StackOverflowError before the constructor body ever gets a chance to execute. Because StackOverflowError is a subtype of Error rather than Exception , the catch clause in main doesn't catch it. Languages in Depth series: Java Programming 11

  12. Animal Farm What does the following Java program print? false Languages in Depth series: Java Programming 12

  13. Animal Farm The “+” operator has higher priority than “==“. The expression could be written :  System.out.println(("Animals are equal: " + pig) == dog); Solution : uses parenthesizes. The expresssion becomes System.out.println("Animals are equal: " + (pig == dog));  It prints “Animal are equal: false”, because == tests objects references, not value Correction : use “equals” method :  System.out.println("Animals are equal: " + pig.equals(dog)); Languages in Depth series: Java Programming 13

  14. Indecisive What does the following Java program print? false Languages in Depth series: Java Programming 14

  15. Indecisive In a try-finally statement, the finally block is always executed when control leaves the try block. When both the try block and the finally block complete abruptly, the reason for the abrupt completion in the try block is discarded. The program tries to return true but finally it returns false . Languages in Depth series: Java Programming 15

  16. Questions? Languages in Depth series: Java Programming 16

  17. Exercise Session 7 Pattern of the Day  Adapter Quizzes Languages in Depth series: Java Programming 17

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