Design Patterns Flashcards
What are the Singleton / Factory design patterns?
Design patterns are independent of any programming languages, so they are an idea rather than an implementation
Singleton: A design pattern that creates a private static instance of a class that needs a get method to access. This makes it so there is only one instance of the class in the JVM. As only one instance of a class is used, we save memory.
Factory: We create an interface or abstract class with method declarations, then we create concrete classes or subclasses to implement the methods and create instances of the class. By using this pattern, we ensure that the actual creation logic is not exposed. Factory design pattern is the most commonly used pattern in Java.
How would you create a Singleton?
- Create a class
- Instantiate a private object of the class
- Create a private constructor and public get method to access the object
- Call get method to retrieve the object from the class
Explain the DAO design pattern
The Data Access Object (DAO) is a pattern used to separate the data persistence logic from the application/business layer. First you create an object class, then an instance to create the