|
1 | 1 | ------------------------------------------------------------------------------------------
|
2 |
| -Software Design and Design Patterns |
| 2 | +Design Patterns |
3 | 3 | ------------------------------------------------------------------------------------------
|
4 | 4 |
|
5 | 5 | 1. What are some alternatives to inheritance?
|
| 6 | + |
| 7 | + One of general recommendations (or some call it OOP design principles) is to favor composition over inheritance. |
| 8 | + For example in strategy pattern the client object is composed with a behavior object (strategy) and this behavior can be changed in runtime. Favoring composition over inheritance leads to a more flexible design. (Of course in each case a separate decision whether to subclass or to compose with an object has to be made. There is no universal approach) |
| 9 | + |
6 | 10 | 2. Give an example where you prefer abstract class over interface ?
|
| 11 | + |
| 12 | + One good example comes from java.awt package. There is an abstract class MouseAdapter that implements several interfaces MouseListener, MouseWheelListener, MouseMotionListener. In general there is no need to write a class that implements all the methods from e.g. MouseListener interface. Instead we can subclass from MouseAdapter and override only the methods that we're interested in. |
| 13 | + |
| 14 | + In general abstract class should be used when there is some default behavior that should be reused. The motivation behind this is changes that are expected to be done in future. If you change some method implementation in an abstract class, all its subclasses will automatically have this updated behavior. If you change an interface -- all classes that implement it will be broken. Another good way to think about abstract class vs interface is thinking about "is a" vs "can be" relation |
| 15 | + |
| 16 | + Example: |
| 17 | + |
| 18 | + TODO: find a good example |
| 19 | + |
7 | 20 | 3. What are wrapper classes? Why do we need wrapper classes?
|
8 |
| -4. Can you please explain “Strategy” design pattern? |
9 |
| -5. Can you please explain “Observer” design pattern? Observer and Observable in Java. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +4. Can you please explain Strategy design pattern? |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +5. Can you please explain Observer design pattern? Observer and Observable in Java |
| 29 | + |
| 30 | + |
| 31 | +. |
10 | 32 | 6. Give example of decorator design pattern in Java ? Does it operate on object level or class level ?
|
| 33 | + |
| 34 | + |
| 35 | + |
11 | 36 | 7. What is Adapter design pattern ? Give examples of adapter design pattern in Java?
|
| 37 | + |
| 38 | + |
| 39 | + |
12 | 40 | 8. What is Chain of Responsibility design pattern ?
|
13 |
| -9. What is Singleton design pattern in Java ? write code for thread-safe singleton in Java |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +9. What is Singleton design pattern in Java ? Write code for thread-safe singleton in Java |
| 45 | + |
| 46 | + |
| 47 | + |
14 | 48 | 10. Give an insight into such patterns as Façade/Proxy/Decorator/Strategy/Observer (selectively)
|
| 49 | + |
| 50 | + |
| 51 | + |
15 | 52 | 11. What is main benefit of using factory pattern ? Where do you use it?
|
16 |
| -12. What is MVC design pattern ? Give one example of MVC design pattern ? |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +12. What is MVC design pattern ? Give one example of MVC design pattern? |
| 57 | + |
| 58 | + |
| 59 | + |
17 | 60 | 13. Which patterns do you use in a daily basis. Explain their principles.
|
| 61 | + |
| 62 | + |
| 63 | + |
18 | 64 | 14. Can you name few design patterns used in standard JDK library? What major patterns do the Java APIs utilize?
|
19 |
| -15. Design a Concurrent Rule pipeline in Java? |
20 |
| -16. Design a Vending Machine which can accept different coins, deliver different products? |
21 |
| -17. You have a Smartphone class and will have derived classes like IPhone, AndroidPhone,WindowsMobilePhone can be even phone names with brand, how would you design this system of Classes. |
22 |
| -18. Design ATM Machine ? |
23 |
| -19. You are writing classes to provide Market Data and you know that you can switch to different vendors overtime like Reuters, wombat and may be even to direct exchange feed , how do you design your Market Data system. |
24 |
| -20. What is FrontController design pattern in Java ? Give an example of front controller pattern ? |
| 65 | + |
| 66 | + Decorator design pattern is widely used in Java IO and to provide unmodifiable and/or synchronized views for collections |
| 67 | + |
| 68 | + TODO: example |
| 69 | + |
| 70 | + Factory methods and factories |
| 71 | + |
| 72 | + TODO: example |
| 73 | + |
| 74 | + Observers are used in java.awt to process keyboard and mouse events |
| 75 | + |
| 76 | + TODO: example |
| 77 | + |
| 78 | + Prototype: clone() method |
| 79 | + |
| 80 | + Strategy: interface Comparable and compare() method |
| 81 | + |
| 82 | + TODO: example |
| 83 | + |
| 84 | + MVC in Swing libraries |
| 85 | + |
| 86 | +15. What is FrontController design pattern in Java ? Give an example of front controller pattern ? |
| 87 | + |
| 88 | +------------------------------------------------------------------------------------------ |
| 89 | +Software Design questions |
| 90 | +------------------------------------------------------------------------------------------ |
| 91 | +1. Design a Concurrent Rule pipeline in Java? |
| 92 | +2. Design a Vending Machine which can accept different coins, deliver different products? |
| 93 | +3. You have a Smartphone class and will have derived classes like IPhone, AndroidPhone,WindowsMobilePhone can be even phone names with brand, how would you design this system of Classes. |
| 94 | +4. Design ATM Machine ? |
| 95 | +5. You are writing classes to provide Market Data and you know that you can switch to different vendors overtime like Reuters, wombat and may be even to direct exchange feed , how do you design your Market Data system. |
0 commit comments