SlideShare uma empresa Scribd logo
1 de 4
UTAH STATE UNIVERSITY
                                        COMPUTER SCIENCE
                                              CS-7350
          Creation Refactoring, based on “Refactoring to Patterns” Chapter 6 by Kerievsky, J.

                                        Jorge Edison Lascano

                                             Spring 2012
                                             02-22-2012

Solving the nonstandard liability.Instead of using creation methods I think that a better way to
refactor many constructors(keeping a standard to instantiate) is passing an object as parameter to
every constructor. I made an experiment with a class Person and constructors to initialize
students, workers and professors; I am assuming no inheritance is needed. The
mechanics(omitting compile and test) is 1) find a class with several constructors:Person, 2)
implement a base constructor:Person(), 3) implement one class per constructor, every class with
an initialization constructor and public attributes as in the original constructors:Student{},
Worker{}, Professor{}, 4) review chained constructors, 5) find all callers and update them to
instantiate with the new constructors (see code).So far I am still using new after refactoring, and
the code looks clearer in the callers; but,with some over-engineering.See attached code for full
java implementation.

PersonaRefactorestRef=new PersonaRefactor(new Student("edi", "SLC",
15, 2));
PersonaRefactorwrkRef=new PersonaRefactor(new Worker("Genie", "Logan",
15, 2,30));
packagejavaperson;

/**
 *
 * @author elascano
 */
public class Main {

    /**
     * @paramargs the command line arguments
     */
public static void main(String[] args) {
        // THIS CODE WITHOUT REFACTORING
        Persona per=new Persona("dani","logan",41);
Persona est=new Persona("edi","logan",41,3);
Persona wrk=new Persona("vicki","logan",41,3,40);
        Persona prf=new Persona("stephen","logan",41,4,20,5);

System.out.println("----------------Persona--------------");
per.print();
System.out.println("----------------Student--------------");
est.print();
System.out.println("----------------Worker--------------");
wrk.print();
System.out.println("----------------Professor--------------");
prf.print();


        // THIS CODE WITH   REFACTORING
PersonaRefactorperRef=new   PersonaRefactor("george","quito",18);
PersonaRefactorestRef=new   PersonaRefactor(new Student("hao", "SLC", 15, 2));
PersonaRefactorwrkRef=new   PersonaRefactor(new Worker("Genie", "Logan", 15, 2,30));
PersonaRefactorprfRef=new   PersonaRefactor(new Professor("Edison", "North Logan", 15, 4, 20, 6));


        //System.out.println("----------------Persona--------------");
        //per.print();
System.out.println("----------------Student--------------");
estRef.print();
System.out.println("----------------Worker--------------");
wrkRef.print();
System.out.println("----------------Professor--------------");
prfRef.print();

    }

}

packagejavaperson;

/**
 *
 * @authorelascano
 */
class Persona {

private String name="";
private String city="";
privateint age=0;
privateintstudyLevel=0;
privateintweekWorkHours=0;
privateinttaughtCourses=0;

    //construct a person
public Persona(String n, String c, int a){
name=n;
city=c;
age=a;
    }

    //contruct a student
public Persona(String n, String c, int a, int l){
        //new Persona(n, c, a);
this(n,c,a);
studyLevel=l;
    }

        //contruct a worker
public Persona(String n, String c, int a, int l, int h){
        //new Persona(n, c, a);
this(n,c,a,l);
weekWorkHours=h;
    }

    //contruct a professor
public Persona(String n, String c, int a, int l, int h, int t){
        //new Persona(n, c, a);
this(n,c,a,l,h);
taughtCourses=t;
    }

public void print(){
System.out.println("name :             "+name);
System.out.println("city :             "+city);
System.out.println("age :              "+age);
System.out.println("level of studies : "+studyLevel);
System.out.println("weekly hours :     "+weekWorkHours);
System.out.println("taught courses :   "+taughtCourses);
    }
}



packagejavaperson;

/**
 *
 * @author elascano
 */
public class PersonaRefactor {

private String name="";
private String city="";
privateint age=0;
privateintstudyLevel=0;
privateintweekWorkHours=0;
privateinttaughtCourses=0;

    //construct a person
publicPersonaRefactor(String n, String c, int a){
name=n;
city=c;
age=a;
    }

    //contruct a student
publicPersonaRefactor(Student S){
        //new Persona(n, c, a);
this(S.name, S.city, S.age);
studyLevel=S.studyLevel;
    }

        //contruct a worker
publicPersonaRefactor(Worker W){
        //new Persona(n, c, a);
this(new Student(W.name, W.city, W.age, W.studyLevel));
weekWorkHours=W.weekWorkHours;
    }

    //contruct a professor
publicPersonaRefactor(Professor P){
        //new Persona(n, c, a);
this(new Worker(P.name, P.city, P.age, P.studyLevel, P.weekWorkHours));
taughtCourses=P.taughtCourses;
    }

public void print(){
System.out.println("name :             "+name);
System.out.println("city :             "+city);
System.out.println("age :              "+age);
System.out.println("level of studies : "+studyLevel);
System.out.println("weekly hours :     "+weekWorkHours);
System.out.println("taught courses :   "+taughtCourses);
    }

}

class Student{
public String name="";
public String city="";
publicint age=0;
publicintstudyLevel=0;

    //construct a person
public Student(String n, String c, int a, int l){
name=n;
city=c;
age=a;
studyLevel=l;
    }
}

class Worker{
public String name="";
public String city="";
publicint age=0;
publicintstudyLevel=0;
publicintweekWorkHours=0;

    //construct a person
public Worker(String n, String c, int a, int l, int h){
name=n;
city=c;
age=a;
studyLevel=l;
weekWorkHours=h;
    }
}

class Professor{
public String name="";
public String city="";
publicint age=0;
publicintstudyLevel=0;
publicintweekWorkHours=0;
publicinttaughtCourses=0;

    //construct a person
public Professor(String n, String c, int a, int l, int h, int t){
name=n;
city=c;
age=a;
studyLevel=l;
weekWorkHours=h;
taughtCourses=t;
    }
}

Mais conteúdo relacionado

Semelhante a Hw11 refactoringcreation

Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Uzair Salman
 
Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...
Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...
Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...Flink Forward
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposalSlavisa Pokimica
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdffashioncollection2
 
React mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Eheinovex GmbH
 
Metaprogramming in JavaScript
Metaprogramming in JavaScriptMetaprogramming in JavaScript
Metaprogramming in JavaScriptMehdi Valikhani
 
Janos Rusiczki - Backbone.js - Models & views in JavaScript
Janos Rusiczki - Backbone.js - Models & views in JavaScriptJanos Rusiczki - Backbone.js - Models & views in JavaScript
Janos Rusiczki - Backbone.js - Models & views in JavaScriptkitsched
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
L11a Create the Student class derived from the Person class- A student.docx
L11a Create the Student class derived from the Person class- A student.docxL11a Create the Student class derived from the Person class- A student.docx
L11a Create the Student class derived from the Person class- A student.docxJacob6ALMcDonaldu
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfjillisacebi75827
 
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersPyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersViach Kakovskyi
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - PraticalsFahad Shaikh
 
Basic OOPs Concepts (E-next.in).pdf
Basic OOPs Concepts (E-next.in).pdfBasic OOPs Concepts (E-next.in).pdf
Basic OOPs Concepts (E-next.in).pdfShubhamMadaan9
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCTomohiro Kumagai
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 

Semelhante a Hw11 refactoringcreation (20)

Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
 
Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...
Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...
Flink Forward Berlin 2018: Jared Stehler - "Streaming ETL with Flink and Elas...
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
 
Ch2
Ch2Ch2
Ch2
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
React mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Ehe
 
Metaprogramming in JavaScript
Metaprogramming in JavaScriptMetaprogramming in JavaScript
Metaprogramming in JavaScript
 
Janos Rusiczki - Backbone.js - Models & views in JavaScript
Janos Rusiczki - Backbone.js - Models & views in JavaScriptJanos Rusiczki - Backbone.js - Models & views in JavaScript
Janos Rusiczki - Backbone.js - Models & views in JavaScript
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
L11a Create the Student class derived from the Person class- A student.docx
L11a Create the Student class derived from the Person class- A student.docxL11a Create the Student class derived from the Person class- A student.docx
L11a Create the Student class derived from the Person class- A student.docx
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
 
6-TDD
6-TDD6-TDD
6-TDD
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
 
Jdbc
Jdbc Jdbc
Jdbc
 
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersPyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
Basic OOPs Concepts (E-next.in).pdf
Basic OOPs Concepts (E-next.in).pdfBasic OOPs Concepts (E-next.in).pdf
Basic OOPs Concepts (E-next.in).pdf
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDC
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 

Mais de Edison Lascano

Hw7 mediator memento observer
Hw7 mediator memento observerHw7 mediator memento observer
Hw7 mediator memento observerEdison Lascano
 
Hw6 interpreter iterator GoF
Hw6 interpreter iterator GoFHw6 interpreter iterator GoF
Hw6 interpreter iterator GoFEdison Lascano
 
Hw5 proxy, chain of responsability, command
Hw5 proxy, chain of responsability, commandHw5 proxy, chain of responsability, command
Hw5 proxy, chain of responsability, commandEdison Lascano
 
Hw4 composite decorator facade flyweight
Hw4 composite decorator facade flyweightHw4 composite decorator facade flyweight
Hw4 composite decorator facade flyweightEdison Lascano
 
Hw12 refactoring to factory method
Hw12 refactoring to factory methodHw12 refactoring to factory method
Hw12 refactoring to factory methodEdison Lascano
 
GoF Patterns: Prototype, Singleton, Adapter, Bridge
GoF Patterns: Prototype, Singleton, Adapter, BridgeGoF Patterns: Prototype, Singleton, Adapter, Bridge
GoF Patterns: Prototype, Singleton, Adapter, BridgeEdison Lascano
 
Abstract Factory and Builder patterns
Abstract Factory and Builder patternsAbstract Factory and Builder patterns
Abstract Factory and Builder patternsEdison Lascano
 
GoF design patterns chapters 1 and 2
GoF design patterns chapters 1 and 2GoF design patterns chapters 1 and 2
GoF design patterns chapters 1 and 2Edison Lascano
 

Mais de Edison Lascano (8)

Hw7 mediator memento observer
Hw7 mediator memento observerHw7 mediator memento observer
Hw7 mediator memento observer
 
Hw6 interpreter iterator GoF
Hw6 interpreter iterator GoFHw6 interpreter iterator GoF
Hw6 interpreter iterator GoF
 
Hw5 proxy, chain of responsability, command
Hw5 proxy, chain of responsability, commandHw5 proxy, chain of responsability, command
Hw5 proxy, chain of responsability, command
 
Hw4 composite decorator facade flyweight
Hw4 composite decorator facade flyweightHw4 composite decorator facade flyweight
Hw4 composite decorator facade flyweight
 
Hw12 refactoring to factory method
Hw12 refactoring to factory methodHw12 refactoring to factory method
Hw12 refactoring to factory method
 
GoF Patterns: Prototype, Singleton, Adapter, Bridge
GoF Patterns: Prototype, Singleton, Adapter, BridgeGoF Patterns: Prototype, Singleton, Adapter, Bridge
GoF Patterns: Prototype, Singleton, Adapter, Bridge
 
Abstract Factory and Builder patterns
Abstract Factory and Builder patternsAbstract Factory and Builder patterns
Abstract Factory and Builder patterns
 
GoF design patterns chapters 1 and 2
GoF design patterns chapters 1 and 2GoF design patterns chapters 1 and 2
GoF design patterns chapters 1 and 2
 

Último

Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment BookingCall Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Bookingnoor ahmed
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingNitya salvi
 
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Call Girls in Nagpur High Profile
 
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...noor ahmed
 
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...noor ahmed
 
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...ritikasharma
 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24... Shivani Pandey
 
Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448ont65320
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...rahim quresi
 
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...aamir
 
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Apsara Of India
 
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...ritikasharma
 
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLBhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLNitya salvi
 
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...noor ahmed
 
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...aamir
 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...SUHANI PANDEY
 
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Riya Pathan
 

Último (20)

Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment BookingCall Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
Call Girls in Barasat | 7001035870 At Low Cost Cash Payment Booking
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
 
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
 
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
 
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
 
Russian ℂall gIRLS In Goa 9316020077 ℂall gIRLS Service In Goa
Russian ℂall gIRLS In Goa 9316020077  ℂall gIRLS Service  In GoaRussian ℂall gIRLS In Goa 9316020077  ℂall gIRLS Service  In Goa
Russian ℂall gIRLS In Goa 9316020077 ℂall gIRLS Service In Goa
 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
 
Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448Beautiful 😋 Call girls in Lahore 03210033448
Beautiful 😋 Call girls in Lahore 03210033448
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
 
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
 
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
 
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goaGoa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
 
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
 
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLBhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
 
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
 
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
 
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
VIP Model Call Girls Budhwar Peth ( Pune ) Call ON 8005736733 Starting From 5...
 
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
 
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Hw11 refactoringcreation

  • 1. UTAH STATE UNIVERSITY COMPUTER SCIENCE CS-7350 Creation Refactoring, based on “Refactoring to Patterns” Chapter 6 by Kerievsky, J. Jorge Edison Lascano Spring 2012 02-22-2012 Solving the nonstandard liability.Instead of using creation methods I think that a better way to refactor many constructors(keeping a standard to instantiate) is passing an object as parameter to every constructor. I made an experiment with a class Person and constructors to initialize students, workers and professors; I am assuming no inheritance is needed. The mechanics(omitting compile and test) is 1) find a class with several constructors:Person, 2) implement a base constructor:Person(), 3) implement one class per constructor, every class with an initialization constructor and public attributes as in the original constructors:Student{}, Worker{}, Professor{}, 4) review chained constructors, 5) find all callers and update them to instantiate with the new constructors (see code).So far I am still using new after refactoring, and the code looks clearer in the callers; but,with some over-engineering.See attached code for full java implementation. PersonaRefactorestRef=new PersonaRefactor(new Student("edi", "SLC", 15, 2)); PersonaRefactorwrkRef=new PersonaRefactor(new Worker("Genie", "Logan", 15, 2,30));
  • 2. packagejavaperson; /** * * @author elascano */ public class Main { /** * @paramargs the command line arguments */ public static void main(String[] args) { // THIS CODE WITHOUT REFACTORING Persona per=new Persona("dani","logan",41); Persona est=new Persona("edi","logan",41,3); Persona wrk=new Persona("vicki","logan",41,3,40); Persona prf=new Persona("stephen","logan",41,4,20,5); System.out.println("----------------Persona--------------"); per.print(); System.out.println("----------------Student--------------"); est.print(); System.out.println("----------------Worker--------------"); wrk.print(); System.out.println("----------------Professor--------------"); prf.print(); // THIS CODE WITH REFACTORING PersonaRefactorperRef=new PersonaRefactor("george","quito",18); PersonaRefactorestRef=new PersonaRefactor(new Student("hao", "SLC", 15, 2)); PersonaRefactorwrkRef=new PersonaRefactor(new Worker("Genie", "Logan", 15, 2,30)); PersonaRefactorprfRef=new PersonaRefactor(new Professor("Edison", "North Logan", 15, 4, 20, 6)); //System.out.println("----------------Persona--------------"); //per.print(); System.out.println("----------------Student--------------"); estRef.print(); System.out.println("----------------Worker--------------"); wrkRef.print(); System.out.println("----------------Professor--------------"); prfRef.print(); } } packagejavaperson; /** * * @authorelascano */ class Persona { private String name=""; private String city=""; privateint age=0; privateintstudyLevel=0; privateintweekWorkHours=0; privateinttaughtCourses=0; //construct a person public Persona(String n, String c, int a){ name=n; city=c; age=a; } //contruct a student
  • 3. public Persona(String n, String c, int a, int l){ //new Persona(n, c, a); this(n,c,a); studyLevel=l; } //contruct a worker public Persona(String n, String c, int a, int l, int h){ //new Persona(n, c, a); this(n,c,a,l); weekWorkHours=h; } //contruct a professor public Persona(String n, String c, int a, int l, int h, int t){ //new Persona(n, c, a); this(n,c,a,l,h); taughtCourses=t; } public void print(){ System.out.println("name : "+name); System.out.println("city : "+city); System.out.println("age : "+age); System.out.println("level of studies : "+studyLevel); System.out.println("weekly hours : "+weekWorkHours); System.out.println("taught courses : "+taughtCourses); } } packagejavaperson; /** * * @author elascano */ public class PersonaRefactor { private String name=""; private String city=""; privateint age=0; privateintstudyLevel=0; privateintweekWorkHours=0; privateinttaughtCourses=0; //construct a person publicPersonaRefactor(String n, String c, int a){ name=n; city=c; age=a; } //contruct a student publicPersonaRefactor(Student S){ //new Persona(n, c, a); this(S.name, S.city, S.age); studyLevel=S.studyLevel; } //contruct a worker publicPersonaRefactor(Worker W){ //new Persona(n, c, a); this(new Student(W.name, W.city, W.age, W.studyLevel)); weekWorkHours=W.weekWorkHours; } //contruct a professor publicPersonaRefactor(Professor P){ //new Persona(n, c, a);
  • 4. this(new Worker(P.name, P.city, P.age, P.studyLevel, P.weekWorkHours)); taughtCourses=P.taughtCourses; } public void print(){ System.out.println("name : "+name); System.out.println("city : "+city); System.out.println("age : "+age); System.out.println("level of studies : "+studyLevel); System.out.println("weekly hours : "+weekWorkHours); System.out.println("taught courses : "+taughtCourses); } } class Student{ public String name=""; public String city=""; publicint age=0; publicintstudyLevel=0; //construct a person public Student(String n, String c, int a, int l){ name=n; city=c; age=a; studyLevel=l; } } class Worker{ public String name=""; public String city=""; publicint age=0; publicintstudyLevel=0; publicintweekWorkHours=0; //construct a person public Worker(String n, String c, int a, int l, int h){ name=n; city=c; age=a; studyLevel=l; weekWorkHours=h; } } class Professor{ public String name=""; public String city=""; publicint age=0; publicintstudyLevel=0; publicintweekWorkHours=0; publicinttaughtCourses=0; //construct a person public Professor(String n, String c, int a, int l, int h, int t){ name=n; city=c; age=a; studyLevel=l; weekWorkHours=h; taughtCourses=t; } }