JPEXS Free Flash Decompiler Issue Tracker

If you are looking for the decompiler itself, visit https://github.com/jindrapetrik/jpexs-decompiler

NEW : We have got a new blog where we post some interesting SWF internals info.

List of issuesList of issues

#2117 Open-Close Principle concerns
Author: user jojusuar
Date created:
Type: other
Visibility: Everybody
Assigned to:
State: new Help

THIS ISSUE IS POSTED AS A COLLEGE ASSIGNMENT ON SOLID DESIGN PRINCIPLES, PLEASE CLOSE THE ISSUE IF YOU FIND IT TO BE USELESS. 1. jpexs-decompiler/libsrc/jpacker/src/com/jpacker/JPacker.java Concern: Line 181 defines the method getEncoding(Option option, Integer base) which returns a JPackerEncoding enum type. It violates OCP by assuming that no new encoding methods with different encoding bases would have to be added later on. Solution: JPackerEncoding could be converted to a class containing a list of every encoding type, as follows: import java.util.ArrayList; abstract class Encoder { protected String name; public abstract Integer getEncodingBase(); } //an example of an implemented encoder with the mentioned attributes class NumericEncoder extends Encoder{ private static Integer encodingBase = 10; public NumericEncoder(){ name = "NUMERIC"; } public String getName(){ return name; } public Integer getEncodingBase(){ return encodingBase; } } class JPackerEncoding { private ArrayList<Encoder> encoders; public JPackerEncoding(){ encoders = new ArrayList<>(); encoders.add(new NumericEncoder()); //add new encoders to this list when implementing them } public ArrayList<Encoder> getEncoders(){ return encoders; } } class JPacker { private static Encoder getEncoding(Option option, Integer base){ JPackerEncoding list = new JPackerEncoding(); for(Encoder e: list.getEncoders()){ if(e.getEncodingBase().equals(base)){ return e; } } return null; } } ****************************************************************************************** ********************** 2. jpexs-decompiler/libsrc/treetable/src/de/hameister/treetable/MyDataModel.java Concern: Line 41 defines the method getValueAt(Object node, int column). It violates OCP by not forseeing the need to consult new attributes in the recieved objects. Solution: An abstract class called Consultable could be extended by all classes of interest, with a List type attribute containing all other attributes in the extending class. The attributes must follow the same order in all classes (ie. lexicographical order). Proposed code could be as follows: import java.util.ArrayList; abstract class Consultable { protected ArrayList<Object> attributes; public abstract ArrayList<Object> getAttributes(); } //example of a consultable class class A extends Consultable{ private String s; private boolean b; private int i; public A(String s, boolean b, int i){ attributes = new ArrayList<>(); this.s = s; attributes.add(s); this.b = b; attributes.add(b); this.i = i; attributes.add(i); } public String getS(){ return s; } public boolean getB(){ return b; } public int getI(){ return i; } public ArrayList<Object> getAttributes(){ return attributes; } } class MyDataModel { public static Object getValueAt(Consultable node, int index){ return node.getAttributes().get(index); } } ****************************************************************************************** *********************** 3. jpexs-decompiler/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java Concern: Line 129 declares the method setStorageType(int storageType). It violates OCP by not considering the possibility of new cache storage types. Solution: Create an enum with all available storage types and implement check logic. Proposed code could be as follows: enum StorageType { STORAGE_FILES, STORAGE_MEMORY; } class Cache { private static StorageType storageType = StorageType.STORAGE_FILES; public static void setStorageType(String type) { if (type.equals(Cache.storageType.toString())) { return; } StorageType temp; for(StorageType t: StorageType.values()){ if(t.toString().equals(type)){ temp = t; } } if(temp==null){ throw new IllegalArgumentException("storageType not recognized"); } if (type.equals(Cache.storageType.toString())) { clearAll(); } Cache.storageType = temp; } } ****************************************************************************************** **********************
Downloadocp 1.png (62 KiB)Downloadocp 2.png (11 KiB)Downloadocp 3.png (13 KiB)