code_junkie

Is it OK to have an 'empty' class that extends another class?

Nov 11th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public class Foo {
  2. /* constructors, fields, method, logic and what-not */
  3. }
  4.  
  5. public class Bar extends Foo {
  6. /* nothing here but constructors */
  7. }
  8.  
  9. public class Bar {
  10. private Foo foo;
  11.  
  12. /* constructors and a bunch of wrapper methods that call
  13. into foo */
  14. }
  15.  
  16. public class Foo {
  17. /* constructors, fields, method, logic and what-not */
  18.  
  19. private boolean isABar; // Could be an enum
  20. }
  21.  
  22. if (foo instanceof Bar) {
  23. // Do Bar-specific things
  24. }
  25.  
  26. class Bar extends AbstractFoo {
  27. public void specialOp() {
  28. // Do Bar-specific things
  29. }
  30. }
  31.  
  32. // ...
  33. foo.specialOp();
  34.  
  35. class FooBarImplementation
  36. {
  37. public void doSomething() { /* etc. */ }
  38. /* etc. */
  39. }
  40.  
  41. class Foo inherits FooBarImplementation { /* etc. */ }
  42. class Bar inherits FooBarImplementation { /* etc. */ }
  43.  
  44. class FooBarImplementation
  45. {
  46. public void doSomething() { /* etc. */ }
  47. /* etc. */
  48. }
  49.  
  50. class Foo
  51. {
  52. private FooBarImplementation fooBarImplementation = new FooBarImplementation() ;
  53.  
  54. public void doSomething() { this.fooBarImplementation.doSomething() ; }
  55. /* etc. */
  56. }
  57.  
  58.  
  59. class Bar
  60. {
  61. private FooBarImplementation fooBarImplementation = new FooBarImplementation() ;
  62.  
  63. public void doSomething() { this.fooBarImplementation.doSomething() ; }
  64. /* etc. */
  65. }
  66.  
  67. Class MainStuff;
  68. Class TypeA;
  69. Class TypeB;
Add Comment
Please, Sign In to add comment