Problem/Motivation

ComplexDataDefinitionBase declares abstract public function getPropertyDefinitions() which made me think that this method is not in the interface, so if my own class does not extend the Base class but just uses the interface, then I don't need to care about implementing that method. That was a false assumption, because the same method is also declared in ComplexDataDefinitionInterface. Bad DX.

Proposed resolution

Remove the declaration from ComplexDataDefinitionBase.

Remaining tasks

User interface changes

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because the behaviour is completely unchanged
Issue priority Minor because DX is slightly improved
Unfrozen changes Not unfrozen according to the written requirements, but the change is trivial to a similar extent.
CommentFileSizeAuthor
#4 2493367-4.patch581 bytesjoshi.rohit100
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joshi.rohit100’s picture

But if a class implements an interface, then it must implement all the interface methods. If we remove the method from the class, it will throw error. Also as per my understanding, if a class doesn't have interface method implementation, then that method and class must declare as abstract.

Arla’s picture

Yes, but the thing is that ComplexDataDefinitionBase is already abstract. It has to, because otherwise it couldn't declare the method as abstract.

joshi.rohit100’s picture

@Arla - thats my point. ComplexDataDefinitionBase is abstract due to the method getPropertyDefinitions() (as it has no defination). Also as it implements the interface, it must decalre (at least signature) that method in class.

joshi.rohit100’s picture

Status: Active » Needs review
FileSize
581 bytes

Please review this :)

Arla’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

cilefen’s picture

Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs beta evaluation

All issues need beta evaluations to be committed in this phase. Please consider the evaluation components carefully to make things easier on the committers.

In order that we can get more people doing reviews, please say a little about what you did to determine this is RTBC. Here is an example of what I did on a similar simple issue.

Arla’s picture

Category: Bug report » Task
Priority: Normal » Minor
Issue summary: View changes
Status: Needs work » Needs review

Inserted beta evaluation.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Status: Needs review » Closed (won't fix)

ComplexDataDefinitionBase implements ComplexDataDefinitionInterface, which declares public function getPropertyDefinitions().

Because the base class wants subclasses to fill in the blanks on getPropertyDefinitions() and thus fulfill the promise of the interface, it declares getPropertyDefinitions() as abstract, so you can't new one into existence without implementing that method.

There might be a reason it doesn't simply follow the lead of getPropertyDefinition() (singular) and make a generic implementation, but I don't know what that reason is.

But as far as the scope of this issue: ComplexDataDefinitionBase seems to be doing the right thing. If it were declaring the method as protected or something it might be wrong, but it's not.

Marking as closed won't fix, but feel free to re-open if my analysis is wrong.

A good separate follow-up issue might be to ask whether getPropertyDefinitions() should have boilerplate code like it's singular pal.

Arla’s picture

it declares getPropertyDefinitions() as abstract, so you can't new one into existence without implementing that method.

It is already abstract as it is declared by ComplexDataDefinitionInterface. This is not breaking coding standards, it's just bad DX. AFAIK, nowhere else do we re-declare a method in an abstract class identically to how it's declared in an interface.

I'm fine with closing the issue. If someone else agrees with me then we can discuss it again.

There might be a reason it doesn't simply follow the lead of getPropertyDefinition() (singular) and make a generic implementation, but I don't know what that reason is.

[...]

A good separate follow-up issue might be to ask whether getPropertyDefinitions() should have boilerplate code like it's singular pal.

As I see it, there's no reason to assume that several complex data definitions would declare similar properties, or generate them in a similar way. Core has only two implementations (EntityDataDefinition and MapDataDefinition) and they have very different implementations.