Reputation: 1622
I've created a project on github that is implementing fingerprint algorithm in PHP. The idea I had is to have parent basic fingerprint implementation and that class to be extended by other more specific classes like City, Company, Title and Street. All of those classes would have specific synonyms and removals (e.g. stopwords) but functionality is the same as base class. All of that is looking fine at this point.
Now, I have a second project, also on github which is creating analyzers, filters and synonyms for Elasticsearch index. It also has parent basic class, that should be extended by other more specific classes like City, Company, Title and Street. Here lies the problem, for each of those specific classes I want to reuse synonyms defined in previous project, respectively.
The version that is seen on github right now is more pseudo code since traits do not work that way (overriding properties is not allowed) but that's the idea what I'm trying to achieve, have common properties and share them between projects.
EDIT: Updated links so it matches current status of the project. Removed traits completely. Using dependency injection now and added some tests for both projects.
Upvotes: 0
Views: 52
Reputation: 58444
The problem stems from your urge to use inheritance, where it is not required. That BaseFP
should have instead been injected as dependency in of your City
, Company
, Title
and Street
classes.
Then you would have been able to extract it as a separate composer package and reused it.
Favor composition over inheritance
Upvotes: 2