Welcome back! You've learned so much about creational patterns, and it's time to apply this knowledge to a real-world project: a banking system. In this unit, we'll focus on using creational patterns to manage and simplify the creation of banking system components in Ruby.
Before we dive in, let's quickly recap the creational patterns we'll use:
- Singleton Pattern: Ensures a class has only one instance and provides a global point of access to it. We'll be using Ruby's built-in
Singleton
module for this purpose. - Factory Method Pattern: Defines an interface for creating an object but allows subclasses to alter the type of objects that will be created. You'll see how Ruby's flexibility enhances the implementation of this pattern.
- Builder Pattern: Separates the construction of a complex object from its representation, allowing the same construction process to create various representations. We'll use it to add further modularity and customization to our system.
We will implement these patterns to create a logger and various types of accounts for our banking system.
Let's see what you'll build in this unit. You will create:
-
Logger with the Singleton Pattern: A logging mechanism that ensures only one instance of the logger exists throughout the application.
-
Accounts using the Factory Method Pattern: Different types of accounts (
savings
andcurrent
) created via a factory method. -
Builder Pattern for Account Reports: A demonstration of using the Builder Pattern to create detailed account reports.
-
Code Integration: Comprehensive integration of these patterns into a cohesive system using Singleton, Factory Method, and Builder patterns.
Example usage:
