Download presentation
Presentation is loading. Please wait.
Published byStephany Hood Modified over 8 years ago
1
Eagleson’s Law: Any code of your own that you haven't looked at for 6+ months might as well have been written by someone else.
2
Computer Science 313 – Advanced Programming Topics
3
How About that Recursion Flat profile of 0.67 secs (32 total ticks): main Interpreted + native Method 3.1% 1 + 0 Recursive02.binomialExpansion Compiled + native Method 96.9% 26 + 5 Recursive02.binomialExpansion Flat profile of 2.61 secs (145 total ticks): main Interpreted + native Method 0.7% 1 + 0 java.util.Vector.elementAt Compiled + native Method 85.5% 118 + 6 Recursive02.binomialExpansion 13.8% 20 + 0 java.util.Vector.addElement
4
What Happened? Why?
5
Simple Explanation Java’s implementation of Stack sucks
6
Real Explanation Java’s Stack slower than system stack Well, duh, but more important is why Stack class must work in lots of situations Includes checks to grow on each call to push Must balance size and speed demands Decent performance often; Great performance never System stack is highly specialized Explodes size to gain speed Benefits from knowing it has only one use
7
One is Special
8
There Can Be Only One! Uniqueness leads to improvements Provide universal access Eliminate unneeded checks for errors Avoid creating large number of small objects Make space-time tradeoffs with confidence Can also make correctness easy Pretty easy to find object triggering error Ensure order of actions Prevents problems over which instance in charge
9
Common Situation Graphic & game engines System.out System.err AbstractFactory instances FactoryMethod instances Device drivers
10
Singleton Pattern Ensures class has exactly 1 instance Always use same instance of class Fields can change, but instance should not Provides single access point to instance All uses of class should go through this Methods should not let this reference leak
11
Singleton Anti-Pattern Process or model harmful to overall process Alcohol Fueled Development Big Ball Of Mud Blowhard Jamboree Design By Committee Kill Two Birds With One Stone Singleton is harmful when a global variable Also known as public static field Can be updated & changed in many places
12
For Next Class Lab #5 on web/Angel & due week from Tues. Implements Decorator pattern & a factory You can choose the factory to implement Read pages 179 – 186 in the book How do we implement these Singletons? What are the myriad ways to screw them up? Which system bugs are exposed by this pattern?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.