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


Groups > comp.programming > #5472

Re: How to name class which will read and write configuration to file

From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
Newsgroups comp.programming
Subject Re: How to name class which will read and write configuration to file
References (1 earlier) <mk4ipq$24r$1@speranza.aioe.org> <9ux9x.13412$HS4.2372@fx07.iad> <mk6cql$u99$1@speranza.aioe.org> <VhH9x.6578$bM1.3874@fx01.iad> <mk7q42$ia6$1@speranza.aioe.org>
Message-ID <BVR9x.13530$QA3.6060@fx18.iad> (permalink)
Date 2015-05-28 21:28 -0700

Show all headers | View raw


On 5/28/15 12:25 PM, August Karlstrom wrote:
> On 2015-05-28 18:23, Daniel Pitts wrote:
>> In particular, the "Single Responsibility Principle" seems relevant
>> here.  A class that represents a Configuration, shouldn't also represent
>> a ConfigurationLoader and ConfigurationSaver.
>
> To me this makes as much sense as saying that a class that represents a
> stack shouldn't also represent a stack pusher and a stack popper.
The property of "being able to push and pop items" is a defining feature 
of a Stack abstraction.  Would you call it a Stack if you couldn't push, 
or pop? I'm going to assume not.

Now, would you call a Configuration class a Configuration if it couldn't 
read itself from a file or write itself out? I'd venture to say you would.

> As I
> see it the configuration class doesn't *represent* a loader or a saver -
> the methods `load' and `save' are just operations on the configuration.

Having the "Loader" and "Saver" operations be handled by distinct 
classes helps in several ways.  Not the least of which is that it 
provides a more flexible design.  It also reduces "clutter" in the 
Configuration class.

If the loading process is complex enough, you could have a bunch of 
private helper methods to go along with the load.  Now you've got many 
lines of code in the Configuration class that isn't related to "being a 
Configuration"


Back to comp.programming | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to name class which will read and write configuration to file pavelkastornii@gmail.com - 2015-05-26 14:39 -0700
  Re: How to name class which will read and write configuration to file August Karlstrom <fusionfile@gmail.com> - 2015-05-27 16:02 +0200
    Re: How to name class which will read and write configuration to file Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2015-05-27 22:13 -0700
      Re: How to name class which will read and write configuration to file August Karlstrom <fusionfile@gmail.com> - 2015-05-28 08:32 +0200
        Re: How to name class which will read and write configuration to file Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2015-05-28 09:23 -0700
          Re: How to name class which will read and write configuration to file August Karlstrom <fusionfile@gmail.com> - 2015-05-28 21:25 +0200
            Re: How to name class which will read and write configuration to file Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2015-05-28 21:28 -0700

csiph-web