Search code examples
javadeprecated

Java : utilization of @Deprecated with Cache Proxy Pattern


I am in the process of creating a library for the teachers' timetable.

But I was wondering if I should put a class in @Deprecated or not.

Here is the case in which I am:

In the library, I have a Schedule class that collects the schedules from the school website.

And another ScheduleProxy class keeps in the cache the requests already made, thus avoiding the same request a second time.

First solution with @Deprecated :

Schedule

/**
 * 
 * @deprecated For the use of the Schedule class, it is preferable
 * to use its proxy: {@link ScheduleProxy} in order to have better response times.
 * 
 * @see InterfaceSchedule
 * @see ScheduleProxy
 */
@Deprecated(forRemoval = false)
public final class Schedule implements InterfaceSchedule {
/*
 * Code
 * 
 */
}

ScheduleProxy

public final class ScheduleProxy implements InterfaceSchedule{
/*
 * Code
 * 
 */
}

Second solution without @Deprecated :

Schedule

I changed the public to private package the Schedule class so the user doesn't use this class.

/**
 * 
 * @see InterfaceSchedule
 * @see Schedule
 */
final class ConcreteSchedule implements InterfaceSchedule {
/*
 * Code
 * 
 */
}

ScheduleProxy

I changed the class name from "ScheduleProxy" to "Schedule" so that it would make it clearer to the library user.

public final class Schedule implements InterfaceSchedule{
/*
 * Code
 * 
 */
}

Question

So I wanted to ask you which of the two solutions is better to use?


Solution

  • The second solution is more intuitive to the user and makes it impossible to use an API you actually don't want to be used. I'd say it's better.