Hi, everybody. I have a question regarding configurable objects.
So, I have this class:
public final class Cached<T>
{
private final Variable<T> variable;
private final Origin<T> origin;
public Cached(Variable<T> variable, Origin<T> origin) {
this.variable = variable;
this.origin = origin;
}
public T value() {
if(!this.variable.initialized()) {
this.variable.initialize(this.origin.value());
}
return this.variable.value();
}
}
It's a class that caches a value. It needs to know what to cache and where to cache it. As you can see, I'm trying to simulate a concept of a variable, where I set a value to it, then reuse it when I need it.
My problem is, I feel this is a configurable object. I'm injecting foreign behaviour in this class through Variable
. It is not a black-box-solid object anymore, a lion's share of its logic is now in the hands of another object. I can pass anything in place of Variable<T>
in the constructor and basically control how this object behaves.
Furthermore, Variable
interface itself reveals a lot of information about Variable
. Since there's a method initialized
and initialize
, I'm almost certain there is an if sentence which checks if a Variable
object holds a value and if it doesn't, sets it. I should not be aware of that.
I discovered this problem while reading one of Yegor's drafts.
Does anyone know what am I supposed to do here? Can't find an alternative.
public final class Cached<T> implements Origin<T>
{
private final List<T> cache = new ArrayList<T>();
private final Origin<T> origin;
public Cached(Origin<T> origin) {
this.origin = origin;
}
public T value() {
if(this.cache.isEmpty()) {
this.cache.add(this.origin.value());
}
return this.cache.get(0);
}
}
@yegor256 "What do you need a man for than?"
Tell that to lesbians that can buy sperm and get pregnant, or simply adopt.
@yegor256 "I got it, but I don't want my daughter to bench someone's desk with one hand and kick someone's ass with the other. I just don't want that :)"
Who the fuck cares what you want? what you should care and what actually matters is what your daugher wants.
@yegor256 And you believe that a society where anyone can be at any position is better than the one where certain people have certain limits?
The only limit there is, is the one you put yourself. None should give a fuck about the limits society puts.
James "Author is a fucking moron. Does he know that a woman invented the first programming language or"
@yegor256 "You made it here: http://www.yegor256.com/tes... Thanks :)"
/Testimonials.html "Author is a fucking moron."
It's funny that in such a small sentence, you leave the good part. Considering some of your testimonials are made of like 15 lines.
@yegor256"I don't have kids yet, but when I will have them I will raise them exactly like my parents raised me: in the gender inequality philosophy.
Translated: In the year 2017, I will raise my kids as kids were raised back in the good old days, where racism, sexism, slavery, all those good things were the norm.
@Yegor256 "We have to live by the laws of the Nature"
No, not really. I live by the laws set by smart/dumb people in my country. That's the only one I actually care.
ArrayList
of 1 and save the value there. But it's not entirely flexible to always save it to a list. Perhaps I want to save it to a file instead or somewhere else etc. Having an abstraction Variable
helps to specify different locations to save the value.
@amihaiemil
When that happens, the "persecuted" one should stand up and debate. Nowadays we just have offended pussies and political correctness... same as in Yegor's article: everyone got offended and misunderstood the point. Everyone thought it was an article about women in tech, when women in tech was a mere example. r"
Did you read the quotes? they are not even from the article. They are from the comments, from yegor - him trying hard to explain himself.
He never said he would discriminate a woman. He just stated his opinion, used only the word "would"... "I would tell her not to work in tech" not "I would stop he
No, I think it's a bit worse, he's fine discriminating any person, according to his ancient style of living.
@fabriciofx Yes, this was my initial design, to have anArrayList
of 1 and save the value there. But it's not entirely flexible to always save it to a list. Perhaps I want to save it to a file instead or somewhere else etc. Having an abstractionVariable
helps to specify different locations to save the value.
ArrayList
....