7 Matching Annotations
- Feb 2021
-
www.infoworld.com www.infoworld.com
-
-
Stating that some language feature or common programming idiom (like accessors) has problems is not the same thing as saying you should never use them under any circumstances.
-
Though getter/setter methods are commonplace in Java, they are not particularly object oriented (OO). In fact, they can damage your code's maintainability. Moreover, the presence of numerous getter and setter methods is a red flag that the program isn't necessarily well designed from an OO perspective.
-
This article explains why you shouldn't use getters and setters (and when you can use them) and suggests a design methodology that will help you break out of the getter/setter mentality.
-
-
en.wikipedia.org en.wikipedia.org
-
Some languages like Smalltalk and Ruby only allow access via object methods
-
- Oct 2020
-
vuejs.org vuejs.org
-
Vue will walk through all of its properties and convert them to getter/setters using Object.defineProperty
-
- Nov 2019
-
webmozart.io webmozart.io
-
Instead of using the empty_data option – which is only called if we create an object, but not if we update it – we will implement a custom data mapper. Symfony's data mappers are responsible for mapping the data of a form to its fields and back. For our MoneyType, Symfony's default data mapper will call the following methods when we display a form with an existing Money instance: $form->get('amount')->setData($money->getAmount()); $form->get('currency')->setData($money->getCurrency()); The properties of the Money are copied to the form simply by calling the appropriate getters. When we submit the form, the data mapper inverts that behavior: $money->setAmount($form->get('amount')->getData()); $money->setCurrency($form->get('currency')->getData()); That's where the data mapper fails. The setters setAmount() and setCurrency() don't exist. To create a custom data mapper we need to implement DataMapperInterface. Let's look at this interface: namespace Symfony\Component\Form; interface DataMapperInterface { /** * Maps properties of some data to a list of forms. * * @param mixed $data Structured data. * @param FormInterface[] $forms A list of {@link FormInterface} instances. */ public function mapDataToForms($data, $forms); /** * Maps the data of a list of forms into the properties of some data. * * @param FormInterface[] $forms A list of {@link FormInterface} instances. * @param mixed $data Structured data. */ public function mapFormsToData($forms, &$data); } These methods correspond to the two previous code blocks. The method mapDataToForms() calls setData() on all passed forms by reading the passed $data. Conversely, mapFormsToData() updates $data by reading the data of the passed forms.
This is so important & useful, when working in DDD & immutability, where setters are avoided.
-