How could I implement Command (Design Pattern) in this work?

3

I'm doing a work in Java where we should implement 3 Design Patterns from the software we created earlier. Home The software I created is basically a CRUD for movies. In a tab, you add (insert) and change (update) the records and in the other tab you have a preview of the records as follows:



Since this work uses the database, I've already used two Design Patterns: Singleton (I've read that it's heavily criticized, etc. but we're only using it to learn it myself) and DAO (I studied it on the internet and I was able to implement it). Home The teacher, if I remember correctly, recommended Command, but I went to read it and could not see a way to fit it into the code. How could I implement it here?

    
asked by anonymous 12.06.2015 / 01:48

1 answer

1

The softest thing to do is the Design Pattern Builder . For example, in the movie class it would look something like this:

class Filme {

   private String nome;
   private Date duracao;
   ...


   /** Setters **/

   public Filme setNome(String nome) {
        this.nome = nome;
        return this;
   }

   public Filme setDuracao(Date duracao) {
        this.duracao = duracao;
        return this;
   }
   .....

}

So it's time to use something like this:

...
    Filme filme = new Filme().setNome("Terminator").setDuracao(duracao);
...

Or so:

...
    Filme filme = new Filme();
    filme.setNome("Terminator").setDuracao(duracao);
...
    
19.06.2015 / 18:29