-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Rename accessor names. #30
base: master
Are you sure you want to change the base?
Conversation
Thanks for the suggestions and you are right, but this library uses a Domain-Driven Design approach and the factories should be immutable. I think in most cases, the factories are created by the service locator. During the planning phase we came to the conclusion to avoid the |
Sadly I wasn't involved in your planning phase, but I'd really like to understand it. Could you elaborate on that? Do you regard those factories as Domain Logic objects? It would go with the rule that the construction should be solely in constructors and accessors should be avoided. I know the limitations of PHP and I predict that you went with getters, instead of just properties, for flexibility; however that doesn't explain why you'd name your getters ambiguously and drop "get" prefix. ? |
I would not say that the factories are domain logic objects. It's not intended that the factory has setters, because it makes no sense to have a dynamic config structure for a factory. You don't have properties for these values too. Why should I have a get method ( It's more a naming design decision. It's like should I use the interface suffix or not? In the first version, there were get methods. But it is unnecessary. Some people have prefixed the getter methods of value objects with get, but why? There are no setter methods with the corresponding name. There are only named constructor methods. |
I supposed the answer to why those are not just $properties is that you wanted to constitute a php interface. Ok, so you wanted to have methods. Example: consider a (factory) class that has multiple methods: class whatever {
public function __construct(){}
public function validate(){}
public function load(){}
} Each method has a purpose, including the PHP magic method of Now let's add some accessors: class whatever {
//public function __construct(){}
//public function validate(){}
//public function load(){}
public function getVersion(){}
public function getTime(){}
public function setMode($mode){}
public function resetTime(){}
} Accessors have self-explanatory name which is somewhat programming language-agnostic and is a general pattern of how you name accessors. It does not matter how many you have, if they're symmetrical for each piece of data, or if they are all setters, getters or other mutators. Even if I removed all mutators, I end up with: class whatever {
public function __construct(){} // ... constructs
public function validate(){} // ... validates
public function load(){} // ... loads
public function getVersion(){} // ... gets version
public function getTime(){} // ... gets time
} The reason for methods to have names it to explain purpose and possible effect. Methods are callable, hence it is a good practice to name them using verbs describing the action. Accessors follow a well-known naming convention ( The only counterargument I found is the normalization of methods with a well known relation - that's why i.e. some SPL classes would truncate accessor name if the relation is static and well defined, so the class cannot operate on anything else but the same type of items. The problem I have in this case is, that |
Just teasing, but why is this I know it changes the meaning, but it seems that this method is named purposefully compared to the other two.
Factories are not value objects. But even if they were, this prefix makes sense for consistency and readability. |
In my PoV interop-container factories doesn't have setters and are stateless at default. Not using the get prefix doesn't mean not to use descriptive names. Let us see if someone else has some suggestions. |
I am with @Thinkscape on this matter. |
This is not BC by a long shot, but I believe the current interface names are awkward.
The change
dimensions()
it should be functiongetDimensions()
options()
it should be functiongetOptions()
Reasoning
Dimensions and options are values on the config (value) object, hence retrieving them via methods is accessing; those methods are called accessors. A common practice is for accessors to be aptly named to recognize their function by prefixing
get
orset
accordingly.Assuming the (config) class contains multiple action methods such as
merge()
performAction()
or evensetOptions()
(i.e. a mutable config) then the interop interface should hint getters with names that describe their purpose:getOptions()
andgetDimensions()
. This makes them less ambiguous and more in line with other libraries and practices.