What Makes Good Code? – Should Every Class Have An Interface? Pt 2

Should Every Class Have an Interface? This is part two in the sub-series of "Should Every Class Have an Interface?", and part of the bigger "What Makes Good Code?" series. Other Peoples' Code So in the last post, we made sure we could get an interface for every class we made. Okay, well that's all fine and dandy (I say half sarcastically). But you and I are smart programmers, so we like to re-use other peoples' code in our own projects. But wait just a second! It looks like Joe Shmoe didn't use interfaces in his API that he created! We refuse to pollute our beautiful interface-rich code with his! What can we do about it? Wrap it. That's right! If we add a little bit of code we can get all the benefits as the example we walked through originally. It's…

1 Comment

Refactoring For Interfaces: An Adventure From The Trenches

Refactoring: Some Background If you're a seasoned programmer you know all about refactoring. If you're relatively new to programming, you probably have heard of refactoring but don't have that much experience actually doing it. After all, it's easier to just rewrite things from scratch instead of trying to make a huge design change part way through, right? In any mature software project, it's often the case where you'll get to a point where your code base in its current state cannot properly sustain large changes going forward. It's not really anyone's fault--it's totally natural. It's impossible to plan absolutely everything that comes up, so it's probable that at some point at least part of your software project will face refactoring. In my real life example, I was tasked with refactoring a software project that has a single owner. I'm close…

1 Comment

Keep Your Fields Private

Background A recent discussion about this spurred a bit of a debate. Ever since I can remember, I've always been told to keep fields private. If you want to expose them any more than private you should use a property. Of course, I was defending my stance on this and figured I should see what other people were saying. I turned to the trusty Stack Overflow (SO) for some answers. Argument For: Control One of the major categories of arguments for keeping fields private has to do with control. Some great points brought up by SO posters included that properties allow you to easily add verification to your data storage. With a field inside of your class, your control is over how this variable is manipulated is constrained to the class. As soon as you expose something outside of the class,…

0 Comments

End of content

No more pages to load