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:
- Use a Form Field. Then they have four properties to define:
- Provide field name
- provide instance of the field
- provide an X-axis Offset
- provide a Y-axis Offset
- Search for a string of text. Then they have four properties to define:
- Provide string of text to search for
- provide instance of that string of text
- provide an X-axis Offset
- provide a Y-axis Offset
- Define Page Coordinates. Then they have three properties to define:
- Provide page number
- provide an X-axis Offset
- 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 = "My String Of Text";
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?
UPDATE
This is what I currently am using because the abstract class thing didn't work.
public class SignatureBlock
{
public List<SignatureBlockPlacement> SignatureBlockPlacements = new List<SignatureBlockPlacement>();
}
public class SignatureBlockPlacement
{
public Enumerations.SignatureBlock.SignatureBlockTypes Type { get; set; }
public string FormField_FieldName { get; set; }
public int FormField_InstanceOfField { get; set; }
public string SearchText_TextToSearch { get; set; }
public int SearchText_InstanceOfText { get; set; }
public string PageCoordinates_PageNumber { get; set; }
public int XOffset { get; set; }
public int YOffset { get; set; }
}
Which I'm implementing like this:
SignatureBlock sigBlock = new SignatureBlock();
SignatureBlockPlacement sig = new SignatureBlockPlacement();
sig.Type = Enumerations.SignatureBlock.SignatureBlockTypes.Signature;
sig.FormField_FieldName = "SignatureField";
sig.FormField_InstanceOfField = 1;
SignatureBlockPlacement title = new SignatureBlockPlacement();
title.Type = Enumerations.SignatureBlock.SignatureBlockTypes.Title;
title.FormField_FieldName = "SignatureField";
title.FormField_InstanceOfField = 1;
title.XOffset = 0;
title.YOffset = -20;
SignatureBlockPlacement org = new SignatureBlockPlacement();
org.Type = Enumerations.SignatureBlock.SignatureBlockTypes.Organization;
org.FormField_FieldName = "SignatureField";
org.FormField_InstanceOfField = 1;
org.XOffset = 0;
org.YOffset = -40;
sigBlock.SignatureBlockPlacements = new List<SignatureBlockPlacement>() { sig, title, org };
If there's a better way to do this, please let me know.
UPDATE #2
I should have mentioned this is for a WCF SOAP web service.
UPDATE #3
Long story short on this one, I need to allow the developer three different ways to place the signature but they should only be allowed to use one of the three ways . Each way shares the X/Y Offset properties but their other properties are unique to each way.
Placement
a subclass of something likeForm
or is it just a class? Do those properties need to be available to an IDE designer, or do they just need to be available to a programmer who is writing code? \$\endgroup\$AddPlacement(...)
function in yourSignatureBlock
class which just adds the new placement to theSignatureBlockPlacement
list. \$\endgroup\$