Tag Info

New answers tagged

0

This code feels like overkill, but it doesn't feel right to have everything public so that anything can change an objects location for example. Encapsulation is part of the problem, but I'd argue that you should design objects with services to clients (responsibilities) which are more abstract than simple methods (sets and gets). setLocation(x,y) is ...


0

The idea is to restrict what objects can modify another object. There are two broad ways to achieve this. Forget it and let anyone modify the objects. Just do not call the mutating functions from outside Level and move on. Use a language feature to achieve this. For example, in C++ you could use the friend keyword to allow Level more access. In Java, you ...


0

A simple solution would be to make them immutable and produce new world objects for the next world state. This gives the Level complete control over the world's state without allowing objects to interfere with each other directly. Another benefit of this approach is that it still works even if your world objects stop being pure data and have some internal ...


0

Whenever casting is a problem for encapsulation depends whenever you have Enabling or Directing attitude. For person with directing attitude, the fact that you can upcast to bypass the encapsulation is definitely a problem, so they probably won't see using an interface as proper encapsulation. But for person with enabling attitude, this is not a problem, ...


1

In layman's words: Writing a solution with OOP is like creating a model of the problem, making the problem look easier, thus allowing to write good enough solutions. But we don't need to model the whole thing down to the most diminute details, because the model would be as complex as the problem itself. That would be like creating a map with a scale of ...


2

I hear that Abstraction is a technique that helps us identify which specific information should be visible, and which information should be hidden. Wrong. Thats still part of encapsulation. Abstraction is when you have multiple interchangeable behaviors that are manipulated through common interface. The multiple thing is the most important thing. In ...


4

In functional programming, there is a concept called Map. Map is a higher-order function that applies a function to each element in a list. In ordinary code, you would do something like: var list = new List<int> { 1,2,3,4,5,6 }; var newList = new List<int>(); foreach(var item in list) { newList.Add(item * 2); } // newList --> { ...



Top 50 recent answers are included