https://github.com/samyam81/fly-weight
This repository contains a Java implementation demonstrating the Flyweight design pattern, which is used to minimize memory usage and improve performance by sharing as much data as possible with related objects.
https://github.com/samyam81/fly-weight
java
Last synced: over 1 year ago
JSON representation
This repository contains a Java implementation demonstrating the Flyweight design pattern, which is used to minimize memory usage and improve performance by sharing as much data as possible with related objects.
- Host: GitHub
- URL: https://github.com/samyam81/fly-weight
- Owner: samyam81
- Created: 2024-05-29T06:36:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-29T07:00:41.000Z (about 2 years ago)
- Last Synced: 2025-01-27T09:14:24.622Z (over 1 year ago)
- Topics: java
- Language: Java
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fly-Weight
This repository contains a Java implementation demonstrating the Flyweight design pattern, which is used to minimize memory usage and improve performance by sharing as much data as possible with related objects. In this example, the Flyweight pattern is applied to a weapon shop scenario.
## Contents
- [Introduction](#introduction)
- [Usage](#usage)
- [Structure](#structure)
## Introduction
The Flyweight pattern is utilized here to optimize the creation and management of various types of guns in a weapon shop. By sharing common parts of gun objects, memory usage is reduced, and performance is improved.
## Usage
To run the application, execute the `Application.java` file located in the `src` directory. This will simulate enumerating the shelves of the weapon shop, showcasing the creation and shooting of different types of guns.
```java
public class Application {
public static void main(String[] args) {
WeaponShop shop = new WeaponShop();
shop.enumerateShelves();
}
}
```
## Structure
The project consists of the following key components:
- `WeaponShop`: Represents the weapon shop where guns are stored and enumerated. It uses the Flyweight pattern to manage guns efficiently.
- `GunFactory`: Implements the Flyweight factory responsible for creating and caching different types of guns.
- `GunType`: Enumerates the various types of guns available in the shop.
- `Shooting`: Defines the interface for shooting behavior.
- Gun implementations (`HandGun`, `Musket`, `Sniper`, `Submachine`): Concrete implementations of different types of guns.
```
Feel free to use or modify it further!
```