I just wrote a CLI (Command Line Interface) app. I do not say finished, because I'm still refactoring it. I have multiple classes in this app. The viewpoints on class responsibility vary. Specifically the interface class responsibility versus the methods class. Some say that you could put puts, inputs and gets methods in whichever class you could justify them.

examples of input, gets, and puts

Others say that they need to be in the CLI class so that if I ever change the project to a web project they will all need to be in the same class and not in the methods class for ease of access.

In my case we are dealing with class CLI and class Photographer. Most of my puts, inputs and gets are in class CLI, but having listened closely to everyone, I have decided that I need to do some refactoring of these methods in class Photographer in order to move the puts to class CLI.

method pic_taker_array
method display
method search_pic_taker_array

First I am going to copy the two methods with the puts statements whole and paste them into the CLI class. Then I have to change a few things to make them a part of class CLI.

The first thing I do after moving pic_taker_array to CLI is change it from a class method to an instance method by removing self. I also need to change the way I call it in the CLI class from Photographer.pic_taker_array to pic_taker_array. Then I put a pry on the first line of this method so that I can see exactly how I need to modify it.

Pry of Photographer.all

I have a method in my Photographer class called self.all that calls @@all so I'm going to try that in my pry. I run the program and see that my photographers are no longer displayed properly.

photographer displays ObjectID instead of Instance

I need to edit the display method so that so that it will accept a photographer into the methods pic_taker, pic_taker_url and orig_url.

method display after alteration

I try running my program again and realize that display is not getting called. This leads me to the line of the glue method where search_pic_taker_array is supposed to be called but is getting skipped, so I decide to take the contents of search_pic_taker_array and move them to glue.

contents of class method search_pic_taker_array
method glue

I run my program and check everything. The photographers display perfectly now!

final refactor

All of the code examples in this article and their associated files can be found here.