Le 17/09/2014 04:26, Sebastian Otaegui a écrit :
> As far as I know "inner classes" are an anti pattern(for the lack of a
> better term)
> 
> Each class should live in its own file.
> 
> More than one class per file is discouraged

I agree. It's better to define "inner classes" in separate files
(my_module::internal1 in my_module/internal1.pp, my_module::internal2
in my_module/internal2.pp etc).

But this is not really my question. My question is: which pattern should
I use:
    a) to define inner classes (indeed in a specific file) 
    b) and to call inner classes in the "my_module" class (which is the
       "top level" class called by the user of my_module)

knowing that a inner class needs to use variables defined in
my_module::params, but among these variables, maybe severals
variables are parameters of the my_module class with a different
value of the default value proposed in my_module::params.

For instance with:

class my_module (
  $var1 = $my_module::params::var1,
  $var2 = $my_module::params::var2,
  $var3 = $my_module::params::var3,
) inherits my_module::params {
    # The body of the class
}  

and:

class my_module::params {

  ## API of the module ##
  $var1 = default_value1
  $var2 = default_value2
  $var3 = default_value3

  ## shared variables between the classes of my_module
  ## but they are not part of the API module
  $foo1 = default_value_foo1
  $foo2 = default_value_foo2
  $foo3 = default_value_foo3
  ...
}

Imagine I want to define an inner class "internal" which
needs to use $var2, $var3, $foo1 and $foo2. Which pattern
should I use to define my "internal" class.

This one?

class my_module::internal (
  $var2,
  $var3,
) inherits my_module::params {

  notify { "value of foo1 -> $foo1": }
  notify { "value of foo2 -> $foo2": }

} 

This one?

class my_module::internal (
  $var2,
  $var3,
) {
  
  require my_module::params
  notify { "value of foo1 -> $my_module:params::foo1": }
  notify { "value of foo2 -> $my_module:params::foo2": }

} 

Or maybe another one...?

In the article that I pointed out in my first message, the
parttern to use to define the "top level" class is clearly
explained. This is:

class my_module (
  # API of my_module
  $var1 = $my_module::params::var1,
  $var2 = $my_module::params::var2,
  $var3 = $my_module::params::var3,
) inherits my_module::params {

    # The body of the class

}  

But the article doesn't explain the pattern to use to define
an inner class (which needs to use variables defined in
my_module::params too and needs to use some variables in
the parameters of my_module class).

I hope I'm clear in my question.
François Lafont


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/541942FD.2020005%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to