Questions tagged [parameter-object]

A design pattern in which multiple method parameters are consolidated in a single object.

The Parameter Object design pattern consolidates multiple method parameters in a single object. The object can validate parameters, provide default values, and give domain meaning to the group of parameters.

More discussion of the pattern is on c2.com.

The Introduce Parameter Object refactoring makes use of this pattern.

14 questions
40
votes
4 answers

Passing single object vs. passing multiple parameters

Suppose I have the following Class A { Foo getFoo(); Bar getBar(); Baz getBaz(); } And I need to define a function doStuff that uses Foo, Bar, Baz of one object and does some stuff I'm struggling between which method of implementing…
Rufus
  • 5,111
  • 4
  • 28
  • 45
9
votes
2 answers

How to create a method parameter object with ReSharper in a few seconds?

Is it possible to select all the parameters of a method and ask ReSharper to create a class from those parameters as a "method parameter object?"
pencilCake
  • 51,323
  • 85
  • 226
  • 363
8
votes
2 answers

Method Parameters vs Parameter Object

I'm trying to build a framework that allows people to extend our core functionality by implementing an interface. Below is a dumbed down example of this interface. public interface MyInterface { IData GetData(string p1, char p2, double…
Michael
  • 3,099
  • 4
  • 31
  • 40
4
votes
3 answers

How do I implement 'Parameter Object' refactor in Python?

Right now I use the parameter object's class to be inherited like so class A(): def __init__(self,p1,p2): self.p1, self.p2 = p1, p2 class B(A): def __init__(self,b): self.p1, self.p2 = b.p1, b.p2 This trims up the absurdity…
bias
  • 1,467
  • 3
  • 19
  • 39
2
votes
4 answers

Create a regular class or an Inner class for a Parameter Object?

Instead of passing many arguments to a method, I was encapsulating it into an argument object. note: simplied for demo For such a case, what would be a better practice? • Create a class and name it as InventorySaveArgs? -- or -- • Create a…
dance2die
  • 35,807
  • 39
  • 131
  • 194
2
votes
1 answer

What are the advantages of extracting parameter objects?

There is a refactoring tool in IntelliJ-IDEA which allows me to extract a parameter object from a method. This will do something like the following: public interface ThirdPartyPoint { float getX(); float getY(); } Before: class Main { …
2
votes
1 answer

Introduce parameter object refactoring in IntelliJ 13

I would like to perform an automatic "Introduce parameter object" refactoring in IntelliJ IDEA 13.1. It seems that this refactoring was available in version 10.5, according to this page, but I can't seem to find it in the current version. In a…
Zoltán
  • 21,321
  • 14
  • 93
  • 134
1
vote
1 answer

How to refactor long parameter lists into a parameter object in Java?

I am currently trying to refactor the getRGB,getSubimage and setRGB methods in the BufferedImage class. I am fairly new to Java and want to create good code; the problem is my parameter list is becoming very long and is causing problems for me. I…
1
vote
3 answers

Are there any anti-pattern names for writing code like this?

Here is some code that uses a parameter class to contain the possible parameters to the Show() method. The values in this FooOption class aren't very related. You can see this by looking at the implementation of Show() below. I know this is bad…
Charles Lambert
  • 5,042
  • 26
  • 47
1
vote
0 answers

Refer to containing object from inside a method parameter object?

Not sure how to phrase the question to be technically correct, but suppose I have an object (outer) that has a method which takes another object (inner) as a parameter - how can I refer to outer from within inner? To clarify what I mean, here's an…
Magnus
  • 17,157
  • 19
  • 104
  • 189
1
vote
1 answer

Using POCO as a parameter object for EntityFramework stored procedure

I would like to use a class example: public class ClassA { public int ID {get;set;} public string Name {get;set;} } as a parameter object to be passed to a stored procedure. this would be a sample of my call List result =…
eBot
  • 117
  • 1
  • 2
  • 10
1
vote
1 answer

How can I use @CookieValue in a Parameter Object Class?

Is it possible to put @CookieValue in a parameter object? I can't seem to get this to work whats is missing? @RequestMapping(value = "/Users", method = RequestMethod.GET) @ResponseBody public Response getAllActiveUsers(CookieParameters…
0
votes
2 answers

Help with a Refactoring: Introduce Parameter Object?

I have some code which is the same except that a certain sequence of assignments happen in slightly different orders. It is easy to factor this out into a method parameter of type int[], which denotes the order. However, I find it isn't the…
Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150
0
votes
2 answers

javascript function parameter object verification

I want to make all my functions take a single object param so I can pass it a list of named arguments independent of order. for example: function A(param){ this.first = param.first ? param.first : null; this.second = param.second ?…
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112