Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #29277

Re: encapsulation problem

From Leif Roar Moldskred <leifm@huldreskog.lan>
Subject Re: encapsulation problem
Newsgroups comp.lang.java.programmer
References <tmv1t9t05ib0u920ul60hdnu6a2noc6q26@4ax.com>
Message-ID <a-2dnQ-yuIg140zOnZ2dnUVZ7vCdnZ2d@giganews.com> (permalink)
Date 2014-07-24 16:46 -0500

Show all headers | View raw


Roedy Green <see_website@mindprod.com.invalid> wrote:
> Let's say you had three enum classes with a considerable amount of
> identical code. 
> 
> What are your options for encapsulation?

Three options:

  1. Don't encapsulate -- keep local copies of the shared logic in 
     each class. This can be the right choice in some situations.

  2. Move the shared logic into a utility class (i.e. static methods)

  3. Move the shared logic into a dedicated type and use instances of
     this type as delegatea in your enums.

A fourth option is to reconsider if enums is the right choice. If you
have a lot of common logic shared between different types of enums,
that's an indication that enums are a poor fit for the underlying problem.


-- 
Leif Roar Moldskred

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

encapsulation problem Roedy Green <see_website@mindprod.com.invalid> - 2014-07-24 05:42 -0700
  Re: encapsulation problem Leif Roar Moldskred <leifm@huldreskog.lan> - 2014-07-24 16:46 -0500
  Re: encapsulation problem Joerg Meier <joergmmeier@arcor.de> - 2014-07-25 00:31 +0200

csiph-web