Skip to main content
added 1 character in body
Source Link
Doc Brown
  • 220.5k
  • 35
  • 410
  • 625

I am reading Martin Fowlers Refactoring book. On page 110 he talks about 'Replace Method with Method Object 'Object' where he turns a method with local variables into a class with instance variavariables.

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers extract methodrefactoring seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?

I am reading Martin Fowlers Refactoring book. On page 110 he talks about 'Replace Method with Method Object ' where he turns a method with local variables into a class with instance varia

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers extract method seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?

I am reading Martin Fowlers Refactoring book. On page 110 he talks about 'Replace Method with Method Object' where he turns a method with local variables into a class with instance variables.

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers refactoring seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?

added 18 characters in body; edited title
Source Link
w0051977
  • 7.1k
  • 8
  • 67
  • 96

Extract Replace Method with Method Object v Principle of Least Visibility

I am reading Martin Fowlers Refactoring book. On page 110 he talks about Extract'Replace Method wherewith Method Object ' where he turns a method with local variables into a class with instance variables.varia

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers extract method seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?

Extract Method v Principle of Least Visibility

I am reading Martin Fowlers Refactoring book. On page 110 he talks about Extract Method where he turns a method with local variables into a class with instance variables.

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers extract method seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?

Replace Method with Method Object v Principle of Least Visibility

I am reading Martin Fowlers Refactoring book. On page 110 he talks about 'Replace Method with Method Object ' where he turns a method with local variables into a class with instance varia

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers extract method seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?

Source Link
w0051977
  • 7.1k
  • 8
  • 67
  • 96

Extract Method v Principle of Least Visibility

I am reading Martin Fowlers Refactoring book. On page 110 he talks about Extract Method where he turns a method with local variables into a class with instance variables.

The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.

I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.

However, Fowlers extract method seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?