Jim McMaster’s Post

View profile for Jim McMaster, graphic

Java Software Engineer

We have a few code smells left. Today, let's talk about Incomplete Library Class. This isn't a problem with *your* code, but is with a library class you are using. That class is just missing some functionality you need. Sometimes, library developers forget something, or you might have a use case they didn't anticipate. If this were your code, you could just add the method. But you might not be willing or able to modify the library. This is especially true when you update the library frequently and would need to add your method(s) with each update. If the function you need is only called from one client class, you can use "Introduce Foreign Method" to add a method to that client class that adds that function. The example Fowler cites is a Date class, where you *really* need a method to get the next date for the one specified. You would add a private Date getNextDate(Date date) method with that capability to the client class. If you need to add several functions, or even one that is called from several client classes, then you would use "Introduce Local Extension". This involves creating either a subclass or a wrapper for the library class, with all the methods you need. Then you would use the extension class in place of the library class wherever you need it. Descriptions of the refactorings are at https://lnkd.in/gxmaYiRv

Encapsulate Collection

Encapsulate Collection

refactoring.com

Andrew Aligizakis

Improving the Functionality, Performance and Reliability of your Information Systems

3mo

I’ve actually created this “code smell” quite a bit, not because there was anything wrong with the library, but because it needed some custom business-specific functionality. Usually something to do with dates and times. Business-specific nonstandard timezones, overlapping schedule times, gaps between times, finding gaps, adjusting schedules to fill gaps or eliminate overlaps, finding overlaps, intervals, sorting etc. The libraries never seem to have enough.

Rayyan Maindargi

"Software Engineer"| "Backend Developer" | "ExpressJS" | "SQL" | "Micro services" | "AWS" | "Kafka" | "Graduate student in Computer Science" |

3mo

Very helpful!

See more comments

To view or add a comment, sign in

Explore topics