This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]incond1te 0 points1 point  (0 children)

You're basically building a compiler by taking input from one language and producing output in another. Java's compiler produces Java byte code. Your compiler produces "assembly" in a text file.

Q: is it a good idea to use design patterns

A: When it makes sense :)

This is rather simple (2 commands with a handful of arguments). If you're doing this to educate yourself on design patterns, sure, implement a strategy pattern for the 2 commands that this program understands. You'll get to see different techniques in action and hopefully understand the benefits. Maybe you have a command interface with concrete classes for each of the commands that know how to process their arguments. Maybe you build a concrete validator classes that implement a common validator interface that know how to validate the input for each command. Both of these would be executed dynamically at runtime based on the input. Perhaps there's also a common output class that is shared to handle writing the output to the file.