Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 313 – Advanced Programming Topics.

Similar presentations


Presentation on theme: "Computer Science 313 – Advanced Programming Topics."— Presentation transcript:

1 Computer Science 313 – Advanced Programming Topics

2  Writing a Java-based file manager  Starts at drive, but drill-down into directories  Print out the names of directories & files  Directory structure shown during print out  Allow user to create & delete files  Print out files sizes as we go

3  Ideas to consider in your design  You’re very lazy (minimize code to write)  Allow future growth for new file system concepts  Take 5 minutes to draw class diagram  Discuss strengths & weaknesses of your design  Make sure you include where methods declared

4  Writing a Java-based file manager  Starts at drive, but drill-down into directories  Print out the names of directories & files  Directory structure shown during print out  Allow user to create & delete files  Print out files sizes as we go

5 Part-Whole Hierarchy

6  Frequently found relationship in real-world: Files – Directory Menu Items – Menu JComponents – JContainer Lines & Figures – Pictures  Instance consists of compositions of single type  Uses component & composite types  Many objects means decorator inappropriate  Invisibility of design is a good idea, however

7 Single Responsibility Principle  Classes should have only one reason to change  Cause errors when writing each responsiblity  Each change increases odds of introducing bug Fixing a bug counts as a change  Ideal classes & methods have 1 purpose  Simple, straight-line code created from ideal cases  Easy to understand code with no side effects  Natural desire to create highly coupled code limited  Design work goal is to enforce SRP

8 Very Common Mistake  Part-whole hierarchy solution violating SRP  Single class for both files & directories  Make complex Client handling 2 classes  Separate add() for Container & Component  Make adding new Components difficult

9 Problem With Simple Solution  Use Composite Pattern to solve situation  Tree-like structure composes part-whole hierarchy  Can be invisible to client if they do not care  Clients that care can use types to see differences

10 For Next Class  Lab available on the web  Try to plan and not wait until Thursday  Due on Friday (e.g., 1 lab period for assignment)  Gets everything set up for look at Map-Reduce algorithm  Read pages 360-380 on Composite Pattern  Will discuss implementation on Friday


Download ppt "Computer Science 313 – Advanced Programming Topics."

Similar presentations


Ads by Google