Archive for May, 2008

Encapsulation or public attributes: but nothing inbetween

Monday, May 19th, 2008

This post asked the question:

Whenever a class in my model contains a collection which requires that particular care be taken with its items, there’s an internal debate regarding how to expose it to other classes. And with this, there are two major schools: one, the paranoia-based approach which doesn’t allow external code to touch the collection’s internal items and two, the trusting approach which just returns the collection for everyone to deal with.

What are your thoughts on the matter? What do you use, when and why?

Definitely paranoia.

It may make certain things more difficult or require more code, but one of the key cornerstones of object-oriented programming is encapsulation and not exposing your internal data in a way that means that others can break it.

If one wants to go for the trust approach - sure it’s easier - but if easiness is the objective one can write a C program and just declare a struct. Then anyone can access the data anyway they want and there’s absolutely no code to write (not even getters and setters). But the world moved away from that model towards encapsulation as with N lines of code (or Nk LOC or NM LOC), without encapsulation, any of those can be responsible for the creation of inconsistent data.

The next few months

Tuesday, May 6th, 2008

I’ve been feeling fairly ill recently. I don’t know what it is, and I’ve been to see various doctors about it. The effects are being constantly so tired that I’m pretty much unable to concentrate on anything. As a consequence I’ve not done much work, and not done much of anything else either.

Plan for the next few months:

  • 8th May - 12th May: break in Thailand
  • 13th May - 20th May: back to Macau: Christina and I are packing her belongings to move to Europe
  • 20th May - approx 1st June: in London with my parents. Various visa things have still to be organized.
  • Whole of June: in Vienna
  • Approx 1st July - 19th July: more preparations for the wedding
  • 20th July - 28th July: honeymoon Maldives
  • Start of August onwards: Vienna