Toxy icon indicating copy to clipboard operation
Toxy copied to clipboard

Restrict access to MessageData internals

Open BasedMan opened this issue 9 years ago • 2 comments

Save for the message string - which is modified during url filtering - no property of MessageData is modified after creation, hence I changed them to be readonly. This approach forces developers to explicitly initialize the object instead of being able to rely on default values. I used named parameters during initialization in order to avoid confusion since there are a lot of bools which have to be passed.

BasedMan avatar May 20 '15 13:05 BasedMan

Wouldn't { get; private set; } suffice too?

alexbakker avatar May 20 '15 13:05 alexbakker

I'm sure it would suffice, however a private setter is a bit less restrictive since an instance can still change its own variables, which it can't do when they are readonly. I am under the impression that immutability is considered "good" practice, which is the reason for this pull request. That being said, it does make the code more complex, so you will have to weigh the advantages and disadvantages when deciding wether you will merge or not.

BasedMan avatar May 20 '15 14:05 BasedMan