DEV Community

loading...
Cover image for Which Class? Puts it in?

Which Class? Puts it in?

Kimberly Kohel-Hayes
I'm an aspiring Software Engineer studying at Flatiron, Treehouse and Freecodecamp.org
Originally published at kak79.github.io Updated on ・3 min read

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.

Alt Text
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.

Alt Text

Alt Text

Alt Text

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 the 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.

Alt Text

Alt Text

I have a method in my Photographer class called self.all that calls @@all so I'm going to try that in my pry.

Alt Text

I run the program and see that my photographers are no longer displayed properly.

Alt Text

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.

Alt Text

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.

Alt Text

Alt Text

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

Alt Text

Discussion (0)