0

I have an application that allows the user to place a string of text into a PDF document. I have three different ways that they can do this:

  1. Use a Form Field. Then they have four properties to define:
    1. Provide field name
    2. provide instance of the field
    3. provide an X-axis Offset
    4. provide a Y-axis Offset
  2. Search for a string of text. Then they have four properties to define:
    1. Provide string of text to search for
    2. provide instance of that string of text
    3. provide an X-axis Offset
    4. provide a Y-axis Offset
  3. Define Page Coordinates. Then they have three properties to define:
    1. Provide page number
    2. provide an X-axis Offset
    3. provide a Y-axis Offset

In my API, I want the object to be setup intuitively so that it is clear they are choose one of the three different methods and then whichever one they choose, they have the options for each.

In my old API, all of those options are grouped together as a list of properties like this:

Placement.FormField_FieldName
Placement.FormField_Instance
Placement.SearchText_Text
Placement.SearchText_Instance
Placement.PageCoordinates_PageNumber
Placement.XOffset
Placement.YOffset

I find this to be a little confusing for the developer using the API because you could never use all of the properties together.

You would either use Form Field like this:

Placement myPlacement = new Placement();
myPlacement.FormField_FieldName = "MyPdfFormFieldName";
myPlacement.FormField_Instance = ;
myPlacement.XOffset = 0;
myPlacement.YOffset = 0;

Or use Text Search like this:

Placement myPlacement = new Placement();
myPlacement.SearchText_Text = "My String Of Text";
myPlacement.FormField_Instance = 1;
myPlacement.XOffset = 0;
myPlacement.YOffset = 0;

Or use Page Coordinates like this:

Placement myPlacement = new Placement();
myPlacement.PageCoordinates_PageNumber = 1;
myPlacement.XOffset = 0;
myPlacement.YOffset = 0;

Is there a better way to setup the class (or sub classes) to make it easier for the developer to understand how to use this functionality?

  • Please, don't cross-post your questions. – svick Feb 21 '14 at 22:44
  • Couldn't delete it or I would have – RichC Feb 27 '14 at 20:09
5

How about:

Placement myPlacement = new FormFieldPlacement("MyPdfFormFieldName", instance, 0, 0);
Placement myPlacement = new TextSearchPlacement("My String Of Text", instance, 0, 0);
Placement myPlacement = new CoordinatePlacement(instance, 0, 0);

Make sure to have sane default arguments though, especially for the offsets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.