Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of this design pattern?

interface Base<T extends Base> {

    T method();
}

Against this pattern design

interface Base {

    Base method();
}

The only, I guess, with method() in Base I can get the specific type. Are there more benefits?

like image 838
rvillablanca Avatar asked Jan 23 '14 18:01

rvillablanca


People also ask

What are the benefits of Web app design patterns?

Web application Design Patterns can help developers not only focus on the application design to build a powerful and functional User Interface for any web application but also to address many common issues even before they happen.

What are the benefits of design patterns implementation documented solutions?

Explanation: Design patterns help one to write the process faster by providing a clearer picture of how one is implementing the design. The Design patterns encourage reuse and accommodate change by supplying well-tested mechanisms for delegation and composition.

Which of the following are the benefits of using the value object design pattern?

The Value Object pattern provides the following general benefits: Better domain modeling and understanding. Recognizing a domain concept as a value type and implementing it as such reduces the gap between the domain model and its implementation. This eases code comprehension.


1 Answers

You just save one cast. Here is an example:

class A implements Base<A> {
    ...
}


A a = ...;
A b = a.method();

vs

class A implements Base {
    ...
}


A a = ...;
A b = (A)a.method();

You can also build on it using T parameter all over the place. Consider accepting T as a parameter or defining a local variable of type T, for example.

like image 192
Boris Brodski Avatar answered Sep 23 '22 21:09

Boris Brodski