Hola Leandro

Entiendo lo que queres hacer, pero una pregunta, porque una clase por cada
mes?
A mi me da la sensación que tu tipo es Mes y que la posición es una
propiedad de una instancia del Mes....
Que aporta tener una clase por cada una?, es mas hasta me da la sensación
que en algún  momento aparece un typeof...

Porque una clase por mes?, que me estoy perdiendo que no entiendo?

Daniel


El 5 de agosto de 2009 10:03, Leandro Tuttini
<[email protected]>escribió:

> hola,
>
> Como continucacion de la primera parte en este caso tengo otra region de
> codigo a optimizar por ahi un poco mas compleja, aunque igualmente tengo
> varias soluciones penmsadas pero queria validarlas a ver si surge alguna
> alternativa aun mejor.
>
> La cuestion es similar a al anterior tratar de evitar el switch.
>
> El codigo seria el siguiente:
>
> Por un lado tengo las siguientes clases:
>
> internal abstract class ExcelMonthPosition
> {
>
>     public abstract string MonthColumn { get; }
>     public abstract string Avance { get; }
>     public abstract List<string> HideColumns { get; }
>
>
>     public string GetMonthLabel()
>     {
>         ...
>     }
>
>
>     public string GetCartera()
>     {
>         ...
>     }
>
>
>     public string GetAvanceByVariable(VariableIdEnum var)
>     {
>         ..
>     }
>
>
> }
>
> internal class ExcelMonth1Position : ExcelMonthPosition
> {
>     public override string MonthColumn { get { return "W"; } }
>
>     public override string Avance { get { return "W"; } }
>
>     public override List<string> HideColumns { get { return new
> List<string>() { "V", "Y" }; } }
> }
>
> internal class ExcelMonth2Position : ExcelMonthPosition
> {
>     public override string MonthColumn { get { return "S"; } }
>
>     public override string Avance { get { return "S"; } }
>
>     public override List<string> HideColumns { get { return new
> List<string>() { "R", "U" }; } }
> }
>
> .
> .
> .
>
> internal class ExcelMonthnPosition : ExcelMonthPosition
> {
>     public override string MonthColumn { get { return "S"; } }
>
>     public override string Avance { get { return "S"; } }
>
>     public override List<string> HideColumns { get { return new
> List<string>() { "R", "U" }; } }
> }
>
>
> Como observaran estas clases permiten definir cada mes y que columnas
> definen a cada uno.
> Hay 12 de estas clases.
>
>
>
>
> Por otro lado esta esta otra funcionalidad:
>
> internal class ExcelPosition
> {
>
>     private short MonthCount = 1;
>
>     public ExcelMonthPosition GetNextMonth()
>     {
>         ExcelMonthPosition excelMonthPosition =
> this.GetMonthByNumber(MonthCount);
>
>         MonthCount++;
>
>         return excelMonthPosition;
>     }
>
>     public ExcelMonthPosition GetMonthByNumber(short monthNumber)
>     {
>         ExcelMonthPosition excelMonthPosition = null;
>
>         switch (monthNumber)
>         {
>             case 1:
>                 excelMonthPosition = new ExcelMonth1Position();
>                 break;
>             case 2:
>                 excelMonthPosition = new ExcelMonth2Position();
>                 break;
>             case 3:
>                 excelMonthPosition = new ExcelMonth3Position();
>                 break;
>             case 4:
>                 excelMonthPosition = new ExcelMonth4Position();
>                 break;
>             case 5:
>                 excelMonthPosition = new ExcelMonth5Position();
>                 break;
>             case 6:
>                 excelMonthPosition = new ExcelMonth6Position();
>                 break;
>             case 7:
>                 excelMonthPosition = new ExcelMonth7Position();
>                 break;
>             case 8:
>                 excelMonthPosition = new ExcelMonth8Position();
>                 break;
>             case 9:
>                 excelMonthPosition = new ExcelMonth9Position();
>                 break;
>             case 10:
>                 excelMonthPosition = new ExcelMonth10Position();
>                 break;
>             case 11:
>                 excelMonthPosition = new ExcelMonth11Position();
>                 break;
>             case 12:
>                 excelMonthPosition = new ExcelMonth12Position();
>                 break;
>         }
>
>         return excelMonthPosition;
>     }
>
> }
>
> Esta es la que se pretende optimizar.
> Como veran por el numero del mes, se obtiene la instancia concreta.
>
> Tengo dos alternativas:
>
> - utilizar reflection para obtener la instancia.
> - crear un diccionario del tipo Dictionary<int, ExcelMonthPosition>, al
> crear la instancia de ExcelPosition, en su constructor (que ahora no tiene),
> cargar ese diccionario que luego se usara en el metodo GetMonthByNumber()
> recuperando la instancia de la posicion dentro del diccionaria
>
> Bueno por ahora solo pense en estas, que opinan, son acertadas? haya alguna
> alternativa aun mejor ?
>
> gracias
> saludos
>
>
> ------------------------------
>
> Encontra las mejores recetas con Yahoo! Cocina.
> http://ar.mujer.yahoo.com/cocina/
>



-- 
Daniel A. Calvin
Cooperator Team Member
http://www.cooperator.com.ar
Microsoft Certified Professional

Responder a