Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen to create a class vs setting a boolean flag?
    primarykey
    data
    text
    <p>I have an interesting question to pose; when should one create a model class/object as opposed to setting a boolean flag for data stored in a database?</p> <p>For example, say I have a Person class that has boolean flags for President, Guard, and PartTime. This class/model is treated differently depending on the value of the flags. So the President gets different privileges in the system from the Guard and from the PartTime(r).</p> <p>When would one use Single Table Inheritance to represent this information and when would one just continue to use the boolean flag?</p> <p>My instinct is to convert these to different Objects using STI since this seems more OO to me. Checking booleans seems wrong in some way, but I can also see a place for it.</p> <p><strong>Update for clarification</strong></p> <p>Let me use another example because the one above has too many cases involved with it.</p> <p>I am working on a CMS application that contains Pages, a Page can be Public, Private, Shared, Hidden, or Default (meaning it is what you get when you don't specify a page in the url). Right now, we have a Page model and everything is a boolean flag - Public, Default, Shared. </p> <p>I am not convinced this is the best method of handling this. Especially since we have rules governing what page can be what, i.e., the Default page or a Shared page must be a Public page whereas a Private page is just Private.</p> <p>I agree with the comment below that Roles for the Person example makes a lot of sense. I am not sure that for the Page example it does.</p> <p>And to make things more complicated, there can only be one Default page and one Shared page. STI may allow me to validate this, but I am not sure since there can be many default and shared pages in the table (just not associated with a particular site).</p> <p><strong>Note</strong>: The context for the question is a Ruby on Rails application, but is applicable for any object-oriented language.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload