Factory methods


Author
Message
Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
Thanks
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I obviously can't speak to what is on the SF web site, but I can let you know how I use factory methods.



Typically I use them in one of two situations:



- There are bunch of ways that an object can be created and constructor overloads are either confusing or don't work (because the arguments wouldn't be unique). In this case it is much easier to create shared (static) factory methods that have clear names and precise arguments. I use it a lot with Forms. I.e. I have a form that can be opened with a single record, or in data entry mode, or with all records that match some criterion and the current record being specified. I could have constructors something like:

public MyForm() {}

public MyForm(int id) {...}

public MyForm(bool dataEntry) {...}

public MyForm(int parentID, int id) {...}




But this is confusing and I have trouble remembering all the permutations. So, instead I would create a set of factory methods:

public static MyForm CreateSingleEdit(int id) {...}

public static MyForm CreateDataEntry() {...}

public static MyForm CreateParentEdit(int parentID, int idToNav) {...}





Now I have no limitation on how complex the constructor is and I have help remembering how I have setup a class.



Hope that provides a bit of clarity. I'm sure others have more/better examples, but I thought I'd get the ball rolling! BigGrin
Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493

From your Web Site ;

"Factory Methods -– Constructors are provided by the BusinessLayer base class that allows the developer to implement custom factories or shared factory methods directly on the business object class."

What is the advantage of Factory Methods ? Could you give me a little bit further information ?

StrataFrame Team
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
There isn't really any information about factory methods in the documentation.  But, creating one would be really simple.  You would want to make the method shared/static, create a new instance of the business object, populate it with the required data, and return it.

public static MyBO SomeFactoryMethod(string param1)
{
    MyBO bo = new MyBO();

    //-- fill the bo

    return bo;
}

Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
In Strataframe documentation, I couldn't find any related information about this topic ?

Could you give us some information ?

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search