I have an interface called Parser . Two classes ParserA, ParserB implement Parser .
public interface Parser{ public void initialize(); public int Parse(byte[] data); }
I have a confusion with initialization. ParserA initializes two Maps . ParserB initializes two Maps . But differentData. Maps initialized with persistent data. The tool is not on time to run.
Therefore Should I use approach 1 or 2?
Approach1:
class Initializer{
Approach2:
class Constants{ //Static initializer of four maps[two for ParserA, two for ParserB] } Class ParserA implements Parser{ public int Parse(byte[] data){ } public void initialize(){ //Constants.map1 likewise use. } } Similarly for class B
Which is preferable in the above use case?
Q2: I have another utility method in the Initializer class. Let it be getAttr that uses these two mappings. In this scenario, which approach is better?
Q3 If I want multiple threads to use these parsers and suppose I choose approach 1, unnecessary intiailization occurs in each thread. This is what really baffles me.
I'm a little confused.
Suppose Animal is the base class for Tiger, Lion . Each Animal will have age, numOfLegs as members. It makes sense to have an Animal class, not age, numOfLegs in every Animal class. So, Superclass wins here. Is not it so? If so, my script also looks like this, I guess.
java
Gops ab
source share