Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Good Java Design pattern/implementation approach suggestion for the below case.

user10494518Nov 27 2015 — edited Nov 27 2015

I have the question regarding the code snippet below.

interface Component{

boolean isRelevant();

}

public abstract class AbstractComponent implements Component {

String componentType;

List<String> data;

public AbstractComponent(String componentType, List<String> data)

{ //assign values. }

}


class ComponentA implements Component {

//Constructor with super method to pass type and data to parent class.

public boolean isRelevant()

{ //Use data to check relevance. }

}

and so on components.

//Main program to Test

List<Component> components; //Initialize all Components with type and data.Ex: new Component("CompA", Data);

Iterate through the Component and run isRelevance over components.

for each component

{

boolean flag = comp.isRelevant()

//HOW DO I Check Component Type here that need to be used in next section as i explained?

}

Secondly based on the combination of Components with true/false, we will arrive with name.

Ex: CompA is relevant, B is relevant and C is not. ===> "Good"

CompA is not relevant, B is relevant and C is not. ===> "Better"

I was thinking of creating a Map with 1/0 bit flags combination and assigning the name.

Say "110" => Good.

Can i have some suggestions on giving a better design/implementation approach for this?

Comments

Processing

Post Details

Added on Nov 27 2015
0 comments
562 views