setter

DDD and the use of Getters and Setters

为君一笑 提交于 2019-12-05 17:45:26
问题 I've read a few articles/posts regarding the use of Getters and Setters, and how they help to defeat the purpose of encapsulation in domain model objects. I understand the logic behind not using setters - you are allowing client code to manipulate attributes of that object, outside the context of the object business rules and invariants. Now this principal does still confuse me. For example, what happens if I need to change the value of a member variable of an object? For example, if the name

Getter & setter support with ng-model in AngularJs

ぃ、小莉子 提交于 2019-12-05 15:15:45
问题 I am trying to get getter/setter support for ng-model by implementing a directive that will take care of getting and setting the values to/from the view/model. I am almost there, but I end up in infinite $digest loops. The idea is to set ng-model="$someFieldToStoreInTheScope", and then have the getter/setter directive do the updates between that field and the getter/setter functions. I use $watch to update the model using the setter expression when the ngModelController updates the field in

When using MVVM pattern, should code relating to property changes go in the setter or an event?

╄→尐↘猪︶ㄣ 提交于 2019-12-05 13:32:28
Looking for guidance on where to place code which is dependent upon changes to a property. For example, I have a view model which is used to hold state for an applications settings public SettingsViewModel(ISettingsRepository settings) { _settings = settings; // ... } For each change to a settings property we have to persist this change to the repository, and on some properties, other properties are affected, so additional code is required. I started off just adding this logic to the setter public ProjectCollection Projects { get { return _projects; } set { if (_projects == value) return;

Why don't the wrapper classes for Primitives have a setter?

北慕城南 提交于 2019-12-05 12:07:15
What is the reason why Wrapper classes (like Integer, Double, etc.) don't have a setter for their inner primitive value ? I am asking this because that kind of functionality would have simplified calculus, and have made the Java language a little more flexible . Let me give you some examples. 1) Let's take the following example: Integer x = new Integer(5); x++; The previous code behind the scenes is performing autoboxing . Something like: int x_tmp = x.intValue(); x_tmp++; x = new Integer(x_tmp); // Yes that's a new memory allocation Because of this problem doing calculus on Wrapper is slower

C# WPF How to set Property setter method dynamically?

与世无争的帅哥 提交于 2019-12-05 09:01:15
I've been searching around but I just can't seem to find what I'm looking for, so I'll give it a go here. Situation: I have the class MainWindow and MainWindowData. In MainWindowData are only public properties defined with the attribute UpdateGUI. public class UpdateGUI : Attribute { } public class MainWindowData { [UpdateGUI] public string TESTVAR { get; set; } } Now I want to add a method to each property's setter method in MainWindowData. More specific: void OnPropertyChanged(String PropertyName); I figured I'd fetch all UpdateGUI properties in the MainWindow constructor, and then somehow

How often do you see abuse of C# shorthand getters/setters?

做~自己de王妃 提交于 2019-12-05 05:31:15
In C# you can create getter/setters in a simpler way than other languages: public int FooBar { get; set; } This creates an internal private variable which you can't address directly, with the external property 'FooBar' to access it directly. My question is - how often do you see this abused? It seems like it has a high potential to violate encapsulation best-practices often. Don't get me wrong, I use it as appropriate, and partial variations of it for read-only write-only types of properties, but what are your unpleasant experiences with it from other authors in your code base? Clarification:

Can you make a method part of the default setter action in a property variable?

允我心安 提交于 2019-12-05 05:31:06
If you have multiple properties that implement the same method in the setter, is there a way to make it part of the default setter? If I have multiple properties that call a Filter() when they are set, is there a way to push it into a "base setter" so that I don't have to have the Filter() call in every setter? private string _MyVal1; public string MyVal1 { get { return _MyVal1; } set { _MyVal1 = value; Filter(); OnPropertyChanged("MyVal1"); } } private string _MyVal2; public string MyVal2 { get { return _MyVal2; } set { _MyVal2 = value; Filter(); OnPropertyChanged("MyVal2"); } } private

Templates for setters and getters

假如想象 提交于 2019-12-05 03:34:37
I am not familiar with templates, but I wonder, if it is possible to use them for setter and getter methods. For example in this situation: double exmlClass::getA(void) const { return a_; } void exmlClass::setA(const double& a) { a_ = a; } double exmlClass::getB(void) const { return b_; } As you can see, methods are almost the same, except they refer to another private variables (a_, b_, c_). Is there a more elegant way to write those functions or it is common practice to do like above in such situations? And if its common to use templates, I would appreciate example how you would use them in

Get and set (private) property in PHP as in C# without using getter setter magic method overloading

限于喜欢 提交于 2019-12-04 23:53:53
问题 Summary Code sample: Class People { // private property. private $name; // other methods not shown for simplicity. } Straight forward. Let me assume that $name is a PRIVATE class member (or property, variable, field, call it as you wish) . Is there any way to do these in PHP: $someone = new People(); $someone->name = $value; $somevar = $someone->name; WITHOUT using __get($name) and __set($name, $value) . Background I needed to check the assigned $value , therefore I simply need a getter

Best practice since JavaFX setters/getters are final?

六眼飞鱼酱① 提交于 2019-12-04 22:02:13
In the process of converting a Windows application from Swing to JavaFX. We had a lot of custom components that previously overrode the mutator methods of JTextField, for example. In JavaFX these methods are declared final. Should I just be creating wrapper methods that call the final methods and modify the values before and after? I just want to make sure I go about doing it the right way from the beginning. Edit: I will also include the fact that some of this code is from much older versions of Java. So it's possible certain things are no longer necessary. This is an example of a setText