Inherit VS include

1,773 views
Skip to first unread message

Kenneth Holter

unread,
Aug 31, 2010, 4:09:03 AM8/31/10
to puppet...@googlegroups.com
Hello all.


Are there any rule of thumb regarding using "inherits" versus "include"? For example, if I'm creating the class "syslog::base" which should servere as a building block for syslog clients, should I go for a "class syslog::client inherits syslog::base { <something> }" or "class syslog::client { include syslog::base }"? 


Best regards,
Kenneth 

Oliver Hookins

unread,
Aug 31, 2010, 7:35:57 AM8/31/10
to Puppet Users
Directly from the horse's mouth (we have training this week)...
Inherits should only be used when you actually intend to use inherits
with overrides. If you don't it makes the code less understandable
than if you just used includes. It's more a code understandability
issue than functionality.

Apparently there are many instances of both questions and good answers
to this question in the group archives too.

Nigel Kersten

unread,
Aug 31, 2010, 11:48:46 AM8/31/10
to puppet...@googlegroups.com
On Tue, Aug 31, 2010 at 4:35 AM, Oliver Hookins <ohoo...@gmail.com> wrote:
> On Aug 31, 10:09 am, Kenneth Holter <kenneho....@gmail.com> wrote:
>> Hello all.
>>
>> Are there any rule of thumb regarding using "inherits" versus "include"? For
>> example, if I'm creating the class "syslog::base" which should servere as a
>> building block for syslog clients, should I go for a "class syslog::client
>> inherits syslog::base { <something> }" or "class syslog::client { include
>> syslog::base }"?
>
> Directly from the horse's mouth (we have training this week)...
> Inherits should only be used when you actually intend to use inherits
> with overrides. If you don't it makes the code less understandable
> than if you just used includes. It's more a code understandability
> issue than functionality.

++

You really don't want to bother with inherits unless you're overriding
resources in the parent.

I still feel like we don't have a good term for "namespace" children
classes, as in a succinct and accurate term for the relationship
between "syslog" and "syslog::foo". They're not child classes, they're
... ?


>
> Apparently there are many instances of both questions and good answers
> to this question in the group archives too.
>

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
>

--
nigel

Jeff McCune

unread,
Aug 31, 2010, 12:55:37 PM8/31/10
to puppet...@googlegroups.com
On Tue, Aug 31, 2010 at 11:48 AM, Nigel Kersten <nig...@google.com> wrote:
> I still feel like we don't have a good term for "namespace" children
> classes, as in a succinct and accurate term for the relationship
> between "syslog" and "syslog::foo". They're not child classes, they're
> ... ?

How about BFF?

Cohorts?

They're all usually part of the same module, so I think something that
indicates that module-level loose relationship would be ideal.

-Jeff

Charles Yeomans

unread,
Aug 31, 2010, 1:33:06 PM8/31/10
to puppet...@googlegroups.com

On Aug 31, 2010, at 11:48 AM, Nigel Kersten wrote:

> On Tue, Aug 31, 2010 at 4:35 AM, Oliver Hookins <ohoo...@gmail.com> wrote:
>> On Aug 31, 10:09 am, Kenneth Holter <kenneho....@gmail.com> wrote:
>>> Hello all.
>>>
>>> Are there any rule of thumb regarding using "inherits" versus "include"? For
>>> example, if I'm creating the class "syslog::base" which should servere as a
>>> building block for syslog clients, should I go for a "class syslog::client
>>> inherits syslog::base { <something> }" or "class syslog::client { include
>>> syslog::base }"?
>>
>> Directly from the horse's mouth (we have training this week)...
>> Inherits should only be used when you actually intend to use inherits
>> with overrides. If you don't it makes the code less understandable
>> than if you just used includes. It's more a code understandability
>> issue than functionality.
>
> ++
>
> You really don't want to bother with inherits unless you're overriding
> resources in the parent.
>
> I still feel like we don't have a good term for "namespace" children
> classes, as in a succinct and accurate term for the relationship
> between "syslog" and "syslog::foo". They're not child classes, they're
> ... ?
>


I might call them "nested classes".


----------------------
Charles Yeomans
Senior Software Engineer
Dakim, Inc.
cha...@dakim.com


Reply all
Reply to author
Forward
0 new messages