SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class naming for different types of enumerators.

    Hello,

    I have a number of classes, where each one tackles a different enumeration as in forms, ie Enabled <> Disabled and Yes <> No selections.

    Both (concrete) classes for example, inherit from a parent class (which in turn, inherits from another parent, but that is besides the point), so can anyone suggest an appropriate name for each class, taking into account that there may well be other such classes.

    If you need to see some script, I'll post later

  2. #2
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not quite sure whats going on. Do you just have classes with consts in them ?

    This reminds me of something I've got to take a look at some point too, the SPLTypes extension, which has a SplEnum class for defining enums, and handing validation.

    http://cvs.php.net/viewvc.cgi/pecl/s....2&view=markup

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, there are no constants (I don't believe in using them) but what I have done, is to put the files onto my laptop, so here is the class hierarchy, as it is at the moment

    PHP Code:
    include_once( 'forms/collections/collections.php' );
        
        final class 
    SelectOptionsEnumeratorTypeA extends SelectOptionCollection {
            protected 
    $array_index;
            
            public function 
    __construct$array_index ) {
                
    $this -> array_index $array_index;
            }
            
            protected function 
    getArrayList() {
                return array(
                    
    0    =>    new Parameters( array(
                        
    'id'    =>    'enabled',
                        
    'name'    =>    'Enabled' ) ),
                    
    1    =>    new Parameters( array(
                        
    'id'    =>    'disabled',
                        
    'name'    =>    'Disabled' ) ) );
            }
        }
        
        final class 
    SelectOptionsEnumeratorTypeB extends SelectOptionCollection {
            protected 
    $array_index;
            
            public function 
    __construct$array_index ) {
                
    $this -> array_index $array_index;
            }
            
            protected function 
    getArrayList() {
                return array(
                    
    0    =>    new Parameters( array(
                        
    'id'    =>    'yes',
                        
    'name'    =>    'Yes' ) ),
                    
    1    =>    new Parameters( array(
                        
    'id'    =>    'no',
                        
    'name'    =>    'No' ) ) );
            }
        }

    include_once( 
    'interfaces/acceptee.php' );
        include_once( 
    'forms/collections/interfaces/collections.php' );
        
        abstract class 
    FormsCollection implements IAcceptee {
            public function 
    __construct() {}
            public function 
    push$acceptable ) {
                
    $acceptable -> import( new Parameters( array( $this -> array_index => $this -> getCollection$acceptable -> request() -> get$this -> array_index ) ) ) ) );
            }
        }
        
        abstract class 
    SelectOptionCollection extends FormsCollection {
            public function 
    __construct() {}
            
            protected function 
    getCollection$selection ) {
                
    $items $this -> getArrayList();
                foreach( 
    $items as $item ) {
                    if( 
    in_array$item -> get'id' ), (array) $selection ) ) {
                        
    $item -> set'selected''selected="selected"' );
                    }
                }
                return 
    $items;
            }
        
            abstract protected function 
    getArrayList();
        }
        
        abstract class 
    CheckBoxCollection extends FormsCollection {
            public function 
    __construct() {}
            
            protected function 
    getCollection$selection ) {
                
    $items $this -> getArrayList();
                foreach( 
    $items as $item ) {
                    if( 
    in_array$item -> get'id' ), (array) $selection ) ) {
                        
    $item -> set'checked''checked="checked"' );
                    }
                }
                return 
    $items;
            }
        
            abstract protected function 
    getArrayList();
        } 
    Does that help?

  4. #4
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, yes. I was thinking of something entirely different, form element attribute (disabled="disabled" type stuff).
    Hmm, still thinking on names tho.

  5. #5
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like a PHP GUI framework for the HTML widgets. However...
    Perhaps some kind of a Hungarian notaton would be applicable, i.e. boolSelector...

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A GUI Framework would be an appropriate description, but the hierarchy as it stands, is just a small part of a larger framework, however there are more options other than those described in my last post, so your suggestion isn't suitable, but thanks for taking the time to add your comments

    Going to take a look at some of Java's API to see what I can learn...

  7. #7
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After all that time, I'm still thinking that the Java API is incredible.
    However I got used to the PHP manual, and never looked back to Java, unfortunately

  8. #8
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I call it enumFieldname (Where fieldname is the name of the form-field) and place it as a method on the controller, or in case of duplicated use, move it into the appropriate model component. I think it's a bit over-design to make it a separate object, but it depends a lot of the rest of the design, I suppose.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •