This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |