Re: Refactoring wishlist

Danijel Arsenovski <[email protected]> Sun, 25 Sep 2011 18:03:44 -0300
Newsgroups gmane.comp.programming.refactoring
Message-ID <CANQVAJJ9MJy42fdhU7K+ajgdXx1y_h5HNghjYvKGAEZMKyrctQ@mail.gmail.com>
I would like to see following refactoring:

1. “Dependency Inversion Refactoring”

Essentially, it is an Extract Interface refactoring where members of newly
created interface are picked based on client usage + “Promote Local to a
Field” refactoring  + Inject Dependency.

Before:

class A {

    public void foo(){

        B b = new B();

        b.bar();

    }

}


class B{

    public void bar() {

        C c = new C();

         c.fizz();

    }

}


class C {

    public  void fizz(){

        //..

    }


    public  void someOtherMethod(){

        //..

    }

}


After:

class A {

    public void foo(){

        B b = new B(new C());

        b.bar();

    }

}


class B{

    public  B(CAsSeenByB cAsSeenByB){

        this.c = cAsSeenByB;

    }


    CAsSeenByB c;

    public void bar() {

       c.fizz();

    }

}


class C implements  CAsSeenByB{

    public  void fizz(){

        //..

    }


    public  void someOtherMethod(){

        //..

    }

}


interface  CAsSeenByB{

        public  void fizz();

}


2. “Inject Dependency”

Starts as “Promote Local to a Field”, then create constructor/property to
inject the dependency and finally instantiate dependency where object is
instantiated:

Before:

class A {

    public void foo(){

        B b = new B();

        b.bar();

    }

}


class B{


    public void bar() {

        C c = new C();

        c.baz();

    }

}


class C {

    public void baz(){

        //..

    }

}


After:

class A {

    public void foo(){

        B b = new B();

        b.setC(new C());

        b.bar();

    }

}


class B{

    private  C c;

    public void bar() {

        c.baz();

    }


    public C getC() {

        return c;

    }


    public void setC(C c) {

        this.c = c;

    }

}


class C {

    public void baz(){

        //..

    }

}


3. There must be some unit-testing specific refactorings, promote local to a
fixture comes to mind, where local variable in a test method is promoted to
a field and initialized in a SetUp method.


4. “Replace Method with Method Object” from classic refactorings would also
be nice



Nice food for thought by the way, thanks Danny.

Danijel Arsenovski
www.empoweragile.com

On Mon, Sep 19, 2011 at 11:03 PM, Danny Dig <[email protected]> wrote:

> **
>
>
> Refactoring tools have made a big splash. They are now in the
> top-level menu (along File, Edit) in most respectable IDEs. On one
> hand, this is good news. On the other, we could have done more.
>
> At every single refactoring workshop that I held in the past, somebody
> inevitably asks the question: "Martin Fowler's catalog lists 90+
> refactorings. More than 10 years after its publication, major IDEs
> like Eclipse only automate about two dozen of those refactorings. When
> are we going to automate the remaining refactorings?".
>
> I would like to automate many more refactorings. This semester I have
> the man-power to do this. I am teaching the Software Engineering
> course at UIUC with 160 students. For the class project, each group of
> 4 students will implement a new refactoring in the Eclipse IDE.
>
> Two kinds of refactorings are worth automating. First, refactorings
> that you perform very infrequently, but are very tricky to get right.
> Second, refactorings that you perform very frequently; you are not
> frustrated because they are complicated, but because you have to do
> them so often by hand.
>
> For the class project we would target refactorings from the latter
> category (simple, but frequent). What are some refactorings that you
> wish we would automate?
>
> best,
> Danny
>
> --
> Danny Dig's homepage: http://netfiles.uiuc.edu/dig/www
>
> Motto: "Success is not for the chosen few but for the few who choose"
>  
>


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/