Pokemon The Clash Of Classes…Edition

David Molina
3 min readDec 13, 2020

--

How it started

I started with the noble pursuit of taking Pokemon Yellow, a 22 year old game, and downgrading the user experience to a CLI application. Not really, there are no gym battles, no pokemon centers, or epic landscapes to traverse. What it does have are pokemon. This ruby gem (pokemon_pokedex) enables you to search through a list of numbers providing information on a pokemon related to that number. It should be simple, find a location to get information from and use different methods to display that information, at least that was the plan.

The API

Finding the PokeAPI was the easy part, it is a robust collection of information one that is not easy to navigate. Let’s start with the information needed to make pokemon_pokedex functional. We need a list of pokemon(specifically from the Kanto Region, 151 Original Pokemon), we also need their description, weight, height, and base stats. The API even provided a handy search bar that would show a JSON parsed response for “easy” navigation.

The API is organized in such a way that the first request would provide a list of names and a url. To get the stats you would need to select the pokemon you wanted and send another request for the desired information. However you don’t receive the description of a pokemon with that request. It is hidden within another URL that would need a separate request. And this is where it all started to fall apart.

This piece of code is the finished product of 6+ hours of finding, checking, asking for assistance, etc. Why yes it is only ten lines, and yes most of those lines could be found within the lessons of accessing an API lesson. Despite the simplicity of it all I found many of my weak points as a novice programmer while working towards the polished product.

Struggling with understanding class responsibility

Now this concept is something I struggle with and have question whether I should create more classes to work together. My initial approach for getting the description and stats were as follows.

Initial Approach(Way Wrong)

Step one. CLI class asks Pokemon class for a find_by_url method to find the url.

Step two. Pokemon class sends url to API class to process

Step three. The API class receive pokemon stats that are sent back Pokemon Class.

Step four. The Pokemon Class assigns attributes to the specific object.

Step five. The Pokemon class sends information about pokemon to CLI and display.

I even had a Table class that would format the information in step five and display it... But essentially I was focused on building relationships and responsibilities to classes that did not need them. Each class does not need to carry the same weight in a method or function. The CLI is in charge of informing the API class it is time to retrieve information, maybe passing an input as a basis. The API class then grabs the information with minor assistance from the Pokemon class. The API class assigns the information to intended Pokemon object and the Pokemon Class stores that information. The Pokemon class is not meant to lift the weight of information rather it is a holder.

As of right now the code is working, The classes are set up, I am not freaking out. I wouldn’t say that my understanding of class responsibilities are perfect or even good. But in comparison to where we were at the beginning there is some progress. Hopefully.

--

--

No responses yet