More Oyster Cards, Encapsulation and Polymorphism
This morning I did some practicals that had been suggested to us. One was about Encapsulation and one was about Polymorphism. I talked about what these were in yesterdays blog, and today I actually got a chance to look at it in practice.
I started with Encapsulation. The first few exercises in the practical were fairly straightforward, I just had to look at methods in a class and group together ones that were similar. Then I had to look at which ones could potentially be moved to a new class. The fourth and final exercise was where it got a little tougher. Using TDD, I had to take some pre-written code and make it totally cohesive, by splitting it into separate classes. It took me a little while to get everything to work together as it should but I did get there eventually! Here is the original code:

And below is the new cohesive code. Here is a link to my repo with all the work in too

After that I started another practical, one focussed on Forwarding and Polymorphism in Object Oriented Code. This was very similar to what I had done in the Creating RSpec practical previously, in fact Polymorphism is basically using Duck Typing to link multiple methods, which is exactly what I did. Because of this it was fairly straightforward. Here is the link to my completed repo. The practical did ask us to do lots of drawings though, which really isn’t my strong point!

In the afternoon we carried on with Oyster Cards. We weren’t given pairs today so I continued on solo. It is definitely getting harder, but the work on Encapsulation and Polymorphism this morning was actually incredibly helpful with the steps that I did today. I guess thats why they were set for us! I have made ok progress today, made it up to challenge 15, which is about separating a few of our methods into their own class. Step 14 was pretty much the same, albeit slightly less complex, but I am hoping that I can get through it with relatively little issue tomorrow!
Here is the song for the day, it was playing in Junkyard Golf when I was there at the weekend, and now it is stuck in my head!

