I'm not sure what IModel<T> is for in that ListView constructor, but the IModel<List<T>> is nice.

About the DropDownChoice, while the clarity is improved there as well, that constructor prevents superclass/subclass type combinations that should be legal.

For example, given the canonical Employee and Manager classes where Manager is a subclass of Employee, the following code won't compile:
        
        // Service method that returns only managers
        public List<Manager> getManagers() {
                ...
        }
        
        // An entity object that holds an employee reference
        public class Company {
                private Employee employee;
                
                public Employee getEmployee() {
                        return this.employee;
                }
        }

        // DropDownChoice declaration that won't compile
        public void test() {
                Company company = new Company();
Model<List<Manager>> managers = new Model<List<Manager>>(getManagers ());
                DropDownChoice<Employee> choice = new 
DropDownChoice<Employee>("id",
new Model<Employee>(company.getEmployee()), managers, new ChoiceRenderer<Employee>());
        }


I don't think this example is too unusual. The types could be dictated by existing code: the service method returns a specific subclass and the entity takes a superclass. We have a lot of combinations like this because we have some pretty deep class hierarchies.

Another problem would be a DropDownChoice<Manager> with a ChoiceRenderer<Employee>, which again doesn't seem too unusual (and we have that situation as well).

Unless my generics-fu is simply not up to snuff, it looks like there could be some real technical issues with generic components in addition to readability and productivity problems with all the time and characters spent declaring types.

This is kind of half-assed, but I think the same level of clarity improvement in those constructors could be achieved with:

ListView(String,IModel,IModel<List>)

and

DropDownChoice(String,IModel,IModel<List>,IChoiceRenderer)

-Ryan

On Mar 19, 2007, at 10:21 PM, Igor Vaynberg wrote:

what about the cases where it is very nice to have?

ListView(String,IModel<T>,IModel<List<T>>)

or

DropDownChoice(String,IModel<T>,IModel<List<T>>,IChoiceRenderer<T>)

im not arguing for or against, but there are cases where it is very nice to have them, especially for newbies. when a newbie looks at the above they
know whats going on as opposed to

DropDownChoice(String,IModel,IModel,IChoiceRenderer)

-igor



Reply via email to