###QueryParser
QueryParser
Right now your query parser has two responsibilities. It parses the query (hence its name), but it also contains the result of the parse, which is kind of unintuitive and violates the Single Responsibility Principle.
I'd create a Query
class that would contain the members com, p1, p2, rel1, rel2
.
If you're not already confortable with polymorphism, I'd try using it to create ErrorCommand
, RetrieveCommand
and AddCommand
instead of just a Query
class. You could use the Command
pattern to separate the responsibilities instead of using the if/else if/else
from the proceedWithQuerry
method.
###RelationshipFactory
RelationshipFactory
This class isn't really a Factory Pattern. In this situation I think you should try to rename it to something else. The only method in the class that kind of fits a Factory
is the populateFamilyTree
method. You could check out the Builder pattern to help build your family tree. It could be an interesting exercise though some people might argue that it's overkill. But as you tagged your question as beginner
, I feel like you could learn something from trying to implement this :)
The int mode
parameter to addRelation
isn't intuitive. I think that it is used to "mirror" the relationship (so that Sibling(Harry,Emma)
would also add Sibling(Emma,Harry)
), this should be made clearer.
###TreeApp
TreeApp
If I'm using your application, how can I know what I'm supposed to enter when this is prompted : System.out.println("Enter option:");
. You should print the options with what they do so that users can use your application.
###General
General
The variable names should be more explicit. Looking at this : String p1;
, how can I know what it will contain? Naming it firstPerson
or something of the like would be good. Short variable names bring nothing of value, especially with IDEs.
###QueryParser
Right now your query parser has two responsibilities. It parses the query (hence its name), but it also contains the result of the parse, which is kind of unintuitive and violates the Single Responsibility Principle.
I'd create a Query
class that would contain the members com, p1, p2, rel1, rel2
.
If you're not already confortable with polymorphism, I'd try using it to create ErrorCommand
, RetrieveCommand
and AddCommand
instead of just a Query
class. You could use the Command
pattern to separate the responsibilities instead of using the if/else if/else
from the proceedWithQuerry
method.
###RelationshipFactory
This class isn't really a Factory Pattern. In this situation I think you should try to rename it to something else. The only method in the class that kind of fits a Factory
is the populateFamilyTree
method. You could check out the Builder pattern to help build your family tree. It could be an interesting exercise though some people might argue that it's overkill. But as you tagged your question as beginner
, I feel like you could learn something from trying to implement this :)
The int mode
parameter to addRelation
isn't intuitive. I think that it is used to "mirror" the relationship (so that Sibling(Harry,Emma)
would also add Sibling(Emma,Harry)
), this should be made clearer.
###TreeApp
If I'm using your application, how can I know what I'm supposed to enter when this is prompted : System.out.println("Enter option:");
. You should print the options with what they do so that users can use your application.
###General
The variable names should be more explicit. Looking at this : String p1;
, how can I know what it will contain? Naming it firstPerson
or something of the like would be good. Short variable names bring nothing of value, especially with IDEs.
QueryParser
Right now your query parser has two responsibilities. It parses the query (hence its name), but it also contains the result of the parse, which is kind of unintuitive and violates the Single Responsibility Principle.
I'd create a Query
class that would contain the members com, p1, p2, rel1, rel2
.
If you're not already confortable with polymorphism, I'd try using it to create ErrorCommand
, RetrieveCommand
and AddCommand
instead of just a Query
class. You could use the Command
pattern to separate the responsibilities instead of using the if/else if/else
from the proceedWithQuerry
method.
RelationshipFactory
This class isn't really a Factory Pattern. In this situation I think you should try to rename it to something else. The only method in the class that kind of fits a Factory
is the populateFamilyTree
method. You could check out the Builder pattern to help build your family tree. It could be an interesting exercise though some people might argue that it's overkill. But as you tagged your question as beginner
, I feel like you could learn something from trying to implement this :)
The int mode
parameter to addRelation
isn't intuitive. I think that it is used to "mirror" the relationship (so that Sibling(Harry,Emma)
would also add Sibling(Emma,Harry)
), this should be made clearer.
TreeApp
If I'm using your application, how can I know what I'm supposed to enter when this is prompted : System.out.println("Enter option:");
. You should print the options with what they do so that users can use your application.
General
The variable names should be more explicit. Looking at this : String p1;
, how can I know what it will contain? Naming it firstPerson
or something of the like would be good. Short variable names bring nothing of value, especially with IDEs.
###QueryParser
Right now your query parser has two responsibilities. It parses the query (hence its name), but it also contains the result of the parse, which is kind of unintuitive and violates the Single Responsibility Principle.
I'd create a Query
class that would contain the members com, p1, p2, rel1, rel2
.
If you're not already confortable with polymorphism, I'd try using it to create ErrorCommand
, RetrieveCommand
and AddCommand
instead of just a Query
class. You could use the Command
pattern to separate the responsibilities instead of using the if/else if/else
from the proceedWithQuerry
method.
###RelationshipFactory
This class isn't really a Factory Pattern. In this situation I think you should try to rename it to something else. The only method in the class that kind of fits a Factory
is the populateFamilyTree
method. You could check out the Builder pattern to help build your family tree. It could be an interesting exercise though some people might argue that it's overkill. But as you tagged your question as beginner
, I feel like you could learn something from trying to implement this :)
The int mode
parameter to addRelation
isn't intuitive. I think that it is used to "mirror" the relationship (so that Sibling(Harry,Emma)
would also add Sibling(Emma,Harry)
), this should be made clearer.
###TreeApp
If I'm using your application, how can I know what I'm supposed to enter when this is prompted : System.out.println("Enter option:");
. You should print the options with what they do so that users can use your application.
###General
The variable names should be more explicit. Looking at this : String p1;
, how can I know what it will contain? Naming it firstPerson
or something of the like would be good. Short variable names bring nothing of value, especially with IDEs.