builder

Builder design pattern with inheritance: is there a better way?

廉价感情. 提交于 2019-12-03 05:06:35
问题 I'm creating a series of builders to clean up the syntax which creates domain classes for my mocks as part of improving our overall unit tests. My builders essentially populate a domain class (such as a Schedule ) with some values determined by invoking the appropriate WithXXX and chaining them together. I've encountered some commonality amongst my builders and I want to abstract that away into a base class to increase code reuse. Unfortunately what I end up with looks like: public abstract

symfony 2.3 form getData doesn't work in subforms collections

谁说胖子不能爱 提交于 2019-12-03 04:35:10
问题 I have a form which contains a collection. So I have: /* my type */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('photos','collection',array( 'type'=> new PhotoType(), 'allow_add'=>true)); } /*Photo Type*/ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('photoname') ->add('size') } But I want to access the data inside the photo, so I tried inside the PhotoType: $data = $builder->getData(); But

Abstract Factory, Factory Method, Builder

半世苍凉 提交于 2019-12-03 02:54:14
问题 It may seem as if this is question is a dupe, but please bear with me - I promise I've read the related posts (and the GOF book). After everything I've read, I still don't have it clear when to use an Abstract Factory, a Factory Method, or a Builder. I believe it will finally sink in after I see a simple example of a problem which is best approached by, say, a builder and it would be clearly silly to use, say, an abstract factory . Can you provide a simple example where you would clearly use

How to open the keyboard automatically on UITextField?

我的未来我决定 提交于 2019-12-03 01:28:25
问题 I have a very simple table and when tocuh a cell it opens a new view with one UITextfield. All I want is that the keyboard will automatically opens, without the user have to touch the UITextfield. Its all done in Interface Builder, so I am not sure how I do this. I guess I need to set the focus at some point ? Thanks 回答1: To cause the keyboard to show up immediately you'll need to set the text field as the first responder using the following line: [textField becomeFirstResponder]; You may

Java Builder pattern and a “deep” object hierarchy

℡╲_俬逩灬. 提交于 2019-12-03 00:37:18
What is the best practice for using Builder pattern in "deep" object hierarchies? To elaborate, I explored the idea of applying the Builder pattern as proposed by Joshua Bloch, to my XML binding code (I am using SimpleXML but this question would apply to any case). My object hierarchy is 4 levels deep, with various degree of complexity. By that, I mean, in some levels I have just a couple of properties for my objects, whereas at some other levels I have up to 10. So consider this hypothetical example (I am leaving out the Simple XML annotations for brevity) public class Outermost { private

Real-world examples of the Builder pattern

丶灬走出姿态 提交于 2019-12-02 23:19:50
I would like to see how is Builder pattern used in real world applications/APIs. The examples I found are all pizzas, cakes, cars et cetera (plus the parser example from the GoF book). Could you please tell me about some usages of this patten in real-world applications/APIs, preferably from the world of C++, .NET or PHP (as those are the languages I'm familiar with). Thanks. Update: I recently came across an even better example (imo). Checkout the JobBuilder and TriggerBuilder implementations in the Quartz scheduler package: http://quartz-scheduler.org/api/2.1.5/ Also, when I have time, just

When I use WebDriverWait rather than Thread.sleep I get a StaleElementReferenceException

╄→尐↘猪︶ㄣ 提交于 2019-12-02 22:41:41
问题 I am trying to write a Selenium object Builder for a Swagger page, in groovy. For the purposes of this discussion, my problem code can be reduced down to the following: class SwaggerBuilder { WebDriver driver def resources SwaggerBuilder(WebDriver driver) { this.driver = driver Thread.sleep(2000) resources = driver.findElements(By.className("resource")).collectEntries { def resourceName = it.findElement(By.tagName("a")).getText().replaceFirst("[/]", "") [(resourceName): it] } } Object

Alter column length in Schema builder?

爱⌒轻易说出口 提交于 2019-12-02 22:28:43
I have two fields i need to increment the character limit on. I're read through the documentation and to my surprise i found no option for it. Is it possible to do? If not, how should i go about solving this? I could drop the column and re-create it with the correct properties, but i don't want to loose any data in the database. Use Raw Queries : /** * Make changes to the database. * * @return void */ public function up() { DB::query('ALTER TABLE mytable MODIFY mycolumn VARCHAR(new-length)'); } /** * Revert the changes to the database. * * @return void */ public function down() { DB::query(

iPhone app converting to iPad? [closed]

纵然是瞬间 提交于 2019-12-02 18:39:29
I want to convert my app to a Universal app. Can anyone recommend some good tutorials for achieving this? I need to have each View in Interface Builder as a separate, view for iPhone or iPad. Thanks in advance! I just did this mostly manually, using approximately the following steps: Load the app's main window xib in Interface Builder, use the IB menu "Create iPad Version" to convert it to an iPad version, and save it under an appropriate name (a "-iPad.xib" suffix is common.) In Xcode, add this new .xib file to your project and include it in the app's target. Modify the app's Info.plist to

Builder design pattern with inheritance: is there a better way?

南楼画角 提交于 2019-12-02 18:20:09
I'm creating a series of builders to clean up the syntax which creates domain classes for my mocks as part of improving our overall unit tests. My builders essentially populate a domain class (such as a Schedule ) with some values determined by invoking the appropriate WithXXX and chaining them together. I've encountered some commonality amongst my builders and I want to abstract that away into a base class to increase code reuse. Unfortunately what I end up with looks like: public abstract class BaseBuilder<T,BLDR> where BLDR : BaseBuilder<T,BLDR> where T : new() { public abstract T Build();