-
-
Notifications
You must be signed in to change notification settings - Fork 566
Introduce abstract base classes for types #78
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
Comments
I love this idea but why not using interfaces instead of abstracts ? |
@mcg-web We can use interfaces of course, but I suspect that type definitions will require some boilerplate code anyway. For example: class AbstractObjectType
{
private $fields;
public function getFields()
{
if (null === $this->fields) {
$this->fields = [
// ...
];
}
return $this->fields;
}
} We can automate it in abstract types. Other thing is that naming is important :) Other option is to put them in separate namespace, but then you will be annoyed by IDE autocomplete with identical names (Exception class names - I am looking at you!) But this is all about brainstorming for now, so maybe we'll stick with interfaces in the end if we can address those issues somehow. |
Ok ok, anyway this will help to add flexibility to types definition(abstract or interface that not a big deal :-) )... |
Abstract would mean there could be no user defined root class :( Why not choose interfaces with boilerplate provided by traits? |
@tpetry Sounds like an argument %) This is exactly the purpose of this issue - to discuss possible use-cases and ideas. Interfaces would work at the cost of more user-land code. So this is really about finding the right balance between ease of use and flexibility. Can you share what traits would you use to reduce boilerplate? Maybe we can include some of them (or at least something similar) in the library so that users do not need to re-invent the same stuff all the time. |
I sm not in need of anyone. That was simply an argument to your position to favor an abstract class indtead of an interface because the abstract class could implement the (possible) boilerplate code someone had to do with an interface. |
@vladar you could have both abstract class, interface + traits or custom user-specific code. Abstract class could just implement interface + use traits. If for some reason users will want some other parent class, they could just use interface. Perfect balance from my point of view. |
Closing stale issues. Open new follow-up issues if required. |
The main goal of this (backwards-compatible) change is to provide better language-level support for type definitions in addition to ConfigBuilder #70 and use less Closures in code.
Example
AbstractObjectType
:AbstractInterfaceType
:Then we could use ConfigBuilder to actually define fields (or stick with arrays for those who prefers it).
It also enables serializable types as field resolution is separated from field definition.
This issue is pretty much created for discussion, so if anyone has any thoughts on the subject - you are very welcome.
The text was updated successfully, but these errors were encountered: