-2

I want to design a subtitle-word parser. It works like that;

  1. Check subtitle provider for availability
  2. Fetch subtitle as inputStream
  3. Convert inputStream to lines of text
  4. Parse lines to sections ( A subtitle file includes 100 - 110 sections )
  5. Parse sections' sentences to words
  6. Save subtitle, section and word to DB

As you see every step follows previous steps output.

Which design pattern(s) I should use?

maskapsiz
  • 244
  • 5
  • 23
  • I think that design patterns refer to something else , rather than what you are trying to do . i would suggest to use the basics of OOP (object oriented programming ) since you are doing it on java . Or you could edit your question and explain what you are reffering to as design - patterns . – Alex Lemesios Dec 05 '18 at 10:39
  • Actually, I know how can I design it using OOP. I am not asking basic of OOP. Every time when I design a system like that I wrote a series of classes which are calling each other like a chain. So I cannot read it after I create. I am not sure which design pattern is suitable for my case. (state design pattern or chain of responsibility or command pattern ) I am asking for which one you can use such a system like that. – maskapsiz Dec 05 '18 at 10:48
  • "I wrote a series of classes which are calling each other like a chain. So I cannot read it after I create" . Consider creating classes with subclasses which implement interfaces . It would minimize chaining / reading complexity . I think that there is no need to use design patterns as such . – Alex Lemesios Dec 05 '18 at 11:18

1 Answers1

0

I'd consider using state design pattern, which is like strategy design pattern but contains current state in its context.

So you'd have something like this:

class ProcessingData {
    private State state = new CheckAvailabilityState();

    //Fill with all data related to the subtitle-word parser


    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }
}

interface State {

    void next(ProcessingData processingData);

    void prev(ProcessingData processingData);

    void execute();

}

class CheckAvailabilityState implements State {
    @Override
    public void next(ProcessingData processingData) {
        processingData.setState(new FetchSubtitlesState());
    }

    @Override
    public void prev(ProcessingData processingData) {
        //this is 1st step so no prev
    }

    @Override
    public void execute() {
        //Availability check goes here ..
    }
}

class FetchSubtitlesState implements State {

    @Override
    public void next(ProcessingData processingData) {
        //ConvertState
    }

    @Override
    public void prev(ProcessingData processingData) {
        processingData.setState(new CheckAvailabilityState());
    }

    @Override
    public void execute() {
        //Fetching goes here ...
    }
}

But I'm not sure about complexity or the need for design patterns considering the problem.

lolo92
  • 63
  • 1
  • 2
  • 8