Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing Implementation Patterns

 
Walter Bernstein
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kent,

I hope you know IntellJ's inspection feature. Do you think it is possible to create inspections that check for the violation of your implementation patterns?

Thanks
Walter
 
Kent Beck
author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Walter,

I am not familiar with IntelliJ's inspections. Assuming they are triggered by a kind of AST matcher, some of the patterns (or their absence) should be detectable.

Regards,

Kent Beck
Three Rivers Institute
 
Michael Hunger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Walter,
actually there are already some inspections that handle patterns of the book. I.e. narrow scope or naming, final parameter/variable, convert field to local and many more intentions. Just take a look at the intention list in the settings and compare them with the implementation patterns.

Others are just sound OO-knowledge and available through the numerous refactorings IDEA offers.
(i.e. extract Interface, Superclass, Encapsulate Fields, Replace Inheritance with Delegation, Move (instance) Method, Find Method duplicates)

It is quite difficult for an IDE to recognize smells that are in the eye of the beholder. It can't know which responsibilities you want to group together, which ones you want to extract and how they relate from the business point of view.

Michael
 
Kent Beck
author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

I think there is more to it than that. For example, I look for multiple messages to the same object in a given method as a hint that the receiving object could use more responsibility. I don't do any fancy business analysis, I just pattern match. I think an automated tool could detect this pattern, but it would have to be fairly sophisticated:
for (X each : Y.Z()) {
Y.W();
}
for example, probably belongs in Y.

Regards,

Kent Beck
Three Rivers Institute
 
Walter Bernstein
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kent Beck:
Michael,

I think there is more to it than that. For example, I look for multiple messages to the same object in a given method as a hint that the receiving object could use more responsibility. I don't do any fancy business analysis, I just pattern match. I think an automated tool could detect this pattern, but it would have to be fairly sophisticated:
for (X each : Y.Z()) {
Y.W();
}
for example, probably belongs in Y.

Regards,

Kent Beck
Three Rivers Institute


"Feature Envy" is already detected. I will check your book to see which inspections are still missing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic