1 / 23

Patterns – Day 9

Patterns – Day 9. Façade Composite Reminders: Faculty candidate talk Friday 4:20 PM O-267. Brian Postow: Games and Complexity Theory Another talk on Monday! Read chapters 6-9 of Metsker. Student-led discussions on specific patterns.

eastham
Download Presentation

Patterns – Day 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Patterns – Day 9 Façade Composite Reminders: Faculty candidate talk Friday 4:20 PM O-267. Brian Postow: Games and Complexity Theory Another talk on Monday! Read chapters 6-9 of Metsker.

  2. Student-led discussions on specific patterns • Give the basic idea of what the pattern is about. (From different sources if possible) • Examples. • Metsker’s examples and challenges • As we go through the patterns, we also want to understand the oozinoz framework, because examples in later patterns might depend on them. • The challenge problems often bring out interesting (and sometimes difficult) issues.

  3. Presentations happening soon We’re doing some chapters out of order, so that I don’t do too many in a row. Not ideal, but the best I can do. Be ready on your “earliest day”. It is possible that it will happen later. It is possible that it will be split.

  4. Questions, comments, rebuttals, etc.?

  5. Façade Pattern • What is it? What is its purpose? • Purpose: To provide a simple interface to services from a complex subsystem.

  6. From wikipedia • There may be a large set of objects with broad uses that are used in conjunction to perform a few functions for client objects. • The façade pattern provides a simplified interface to achieve only those functions needed without having to reference many different, complicated interfaces. • The result is a simple feel to a complicated process.

  7. GoF Compiler Example

  8. Metsker definition • a facade is a class with methods that make it easy to use the classes in a subsystem.

  9. Metsker example – dud rockets C:\Documents and Settings\anderson\My Documents\Courses\Patterns\oozinoz\code\com\oozinoz\applications\FLightPanel_1.java • FlightPanel_1 does too many things: • Window for displaying picture • Trajectory calculations • Application class’

  10. Challenge 4.1 Complete the diagram in Figure 4.4 to show the code for FlightPanel_1 refactored into three classes: a FlightPath class, a reduced FlightPanel class that draws a flight path, and a SwingFacade class. Provide the facade with the utility methods that appeared in the initial FlightPanel_1 class. Also provide the facade with a method to launch a frame.

  11. Challenge 4.1-solution Complete the diagram in Figure 4.4 to show the code for FlightPanel_1 refactored into three classes: a FlightPath class, a reduced FlightPanel class that draws a flight path, and a SwingFacade class. Provide the facade with the utility methods that appeared in the initial FlightPanel_1 class. Also provide the facade with a method to launch a frame.

  12. A problem • A beginning Java student wants to run a program that requires a line or two of interactive user input. • We can give the magic incantations: • BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); • String oneLine;while( ( oneLine = in.readLine( ) ) != null) • but this requires a lot of explanation that the student doesn’t need yet and is probably not ready for. • or we can …

  13. Consider this example • Run this example: • c:\Documents and Settings\anderson\My Documents\courses\Patterns\Lectures\Facade\facade • Which classes are involved? • Does Swing provide a façade for this?

  14. A Swing Façade: JOptionPane

  15. JOptionPane Example It is in the class examples directory.

  16. Other façade examples/comments?

  17. Composite Pattern • Metsker definition: • A composite is a group of objects in which some objects may contain others; thus, one object may represent groups, and another may represent an individual item, or leaf • Examples: • (fill then in)

  18. Advantages of Composite • Groups can contain groups or individuals. • There can be common behaviors for groups and individuals. • Remember slist-recur from PLC? • So a group and an individual can present the same interface.

  19. Challenge 5.2 • The factory is composed of bays; each bay has one or more manufacturing lines; a line is a collection of machines that collaboratively produce material to meet a schedule. • The developers at Oozinoz have modeled this composition from the problem domain with the class structure shown in Figure 5.2. • As the figure shows, thegetMachineCount()behavior applies to both individual machines and collections of machines and returns the number of machines in any given component. CHALLENGE 5.2Write the code for the getMachineCount() methods implemented by Machine and by MachineComposite.

  20. Additional methods for Machines and MachineComponents CHALLENGE 5.3For each method declared by MachineComponent, give recursive definitions for MachineComposite and nonrecursive definitions for Machine.

  21. Non-tree-structured layouts No cycles, but not a tree. What’s the common name for this kind of structure? CHALLENGE 5.4What does the following program print out?

  22. Detecting “non-treeness” CHALLENGE 5.5Write the code for MachineComposite.isTree(Set s) . Does that code work if there are cycles in the graph?

More Related