Skip to content

Instantly share code, notes, and snippets.

View selvamani-k-8445's full-sized avatar
🎯
Focusing

selvamani-k-8445 selvamani-k-8445

🎯
Focusing
View GitHub Profile
package FlyWeight;
public class Demo {
public static void show() {
SpreadSheet sheet = new SpreadSheet();
sheet.setContent(0, 0, "Hello");
sheet.setContent(1, 0, "World");
sheet.setFontFamily(0, 0, "Arial");
sheet.render();
}
package FlyWeight;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class CellPropertyFactory {
Map<Integer, CellProperty> map;
CellPropertyFactory(){
map = new HashMap<>();
package FlyWeight;
import java.util.Objects;
public class CellProperty {
private final String fontFamily;
private final int fontSize;
private final boolean isBold;
CellProperty(String fontFamily,int fontSize,boolean isBold){
package FlyWeight;
public class SpreadSheet {
private final int MAX_ROWS = 3;
private final int MAX_COLS = 3;
private CellPropertyFactory factory = new CellPropertyFactory();
// In a real app, these values should not be hardcoded here.
// They should be read from a configuration file.
private final String fontFamily = "Times New Roman";
private final int fontSize = 12;
@selvamani-k-8445
selvamani-k-8445 / Cell.java
Created October 16, 2022 12:31
FlyweightPattern
package FlyWeight;
public class Cell {
private final int row;
private final int column;
private String content;
private CellProperty properties;
public Cell(int row, int column,CellProperty properties) {
this.row = row;