Thursday, March 26, 2015

Using composition over inheritance when overriding

interface SomeMethods {
  void doSomething();
  void doSomethingElse();
}

class Foo implements SomeMethod {
  public void doSomething() { // implementation }
  public void doSomethingElse() { // implementation }
}

class Bar implements SomeMethod {
   private final Foo foo = new Foo();

   public void doSomething() { foo.doSomething(); }
   public void doSomethingElse() { // do something else! }
}

Popular Posts

Labels

ad ( 3 ) Amazon ( 47 ) Answer ( 1 ) API ( 25 ) automation ( 1 ) blog ( 23 ) book ( 2 ) career ( 12 ) cdn ( 2 ) centos ( 1 ) cloud ( 123 ) CRM ( 24 ) current ( 10 ) data ( 14 ) database ( 64 ) design patterns ( 14 ) development ( 3 ) eCommerce ( 25 ) email ( 94 ) ETL ( 2 ) framework ( 3 ) git ( 9 ) google ( 179 ) IDE ( 12 ) Integration ( 1 ) interview ( 15 ) Java ( 381 ) Java EE ( 105 ) javascript ( 43 ) Jboss ( 4 ) JPA ( 48 ) JSF ( 45 ) linux ( 338 ) Marketing ( 19 ) mobile ( 43 ) model ( 1 ) MySQL ( 198 ) online money ( 12 ) OOP ( 7 ) open source ( 26 ) performance ( 71 ) php ( 51 ) python ( 47 ) quality ( 5 ) referral ( 3 ) restful ( 23 ) security ( 126 ) SEO ( 18 ) social ( 26 ) software ( 72 ) spam ( 4 ) Spring ( 1 ) SQL ( 22 ) system ( 29 ) testing ( 17 ) tool ( 90 ) UML ( 8 ) virtual ( 10 ) web ( 223 ) web services ( 14 ) WildFly ( 4 ) wordpress ( 9 )