fluent-interface

Fluent interface in Delphi

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 02:18:21
问题 What are the pros and cons in using fluent interfaces in Delphi? Fluent interfaces are supposed to increase the readability, but I'm a bit skeptical to have one long LOC that contains a lot of chained methods. Are there any compiler issues? Are there any debugging issues? Are there any runtime/error handling issues? Fluent interfaces are used in e.g. TStringBuilder, THTMLWriter and TGpFluentXMLBuilder. Updated: David Heffernan asked which issues I was concerned about. I've been given this

What's the point of DSLs / fluent interfaces

廉价感情. 提交于 2019-12-02 19:10:58
I was recently watching a webcast about how to create a fluent DSL and I have to admit, I don't understand the reasons why one would use such an approach (at least for the given example). The webcast presented an image resizing class, that allows you to specify an input-image, resize it and save it to an output-file using the following syntax (using C#): Sizer sizer = new Sizer(); sizer.FromImage(inputImage) .ToLocation(outputImage) .ReduceByPercent(50) .OutputImageFormat(ImageFormat.Jpeg) .Save(); I don't understand how this is better than a "conventional" method that takes some parameters:

Can I have an abstract builder class in java with method chaining without doing unsafe operations?

ε祈祈猫儿з 提交于 2019-12-02 17:33:33
I'm trying to have an abstract base class for some builder classes so I can easily reuse code between the Builder implementations. I want my builders to support method chaining therefore a method has to return "this" instance of the most specific type. I figured I could probably do this with generics. Unfortunatly I did not manage to do it without using unsafe operations. Is it possible? Sample code of how I'm trying it (and how it works) below. I'd like to avoid casting to T in "foo()" (which causes an unchecked warning), can this be done? public class Builders { public static void main(

Design of an Alternative (Fluent?) Interface for Regular Expressions

狂风中的少年 提交于 2019-12-02 16:17:13
I've just seen a huge regex for Java that made me think a little about maintainability of regular expressions in general. I believe that most people - except some badass perl mongers - would agree that regular expressions are hardly maintainable. I was thinking about how this situation could be fixed. So far, the most promising idea I have is using a fluent interface . To give an example, instead of: Pattern pattern = Pattern.compile("a*|b{2,5}"); one could write something like this import static util.PatternBuilder.* Pattern pattern = string("a").anyTimes().or().string("b").times(2,5).compile

Fluent interface in Delphi

ⅰ亾dé卋堺 提交于 2019-12-02 15:49:25
What are the pros and cons in using fluent interfaces in Delphi? Fluent interfaces are supposed to increase the readability, but I'm a bit skeptical to have one long LOC that contains a lot of chained methods. Are there any compiler issues? Are there any debugging issues? Are there any runtime/error handling issues? Fluent interfaces are used in e.g. TStringBuilder , THTMLWriter and TGpFluentXMLBuilder . Updated: David Heffernan asked which issues I was concerned about. I've been given this some thought, and the overall issue is the difference between "explicitly specifying how it's done"

Creating Many To Many Relationships using Fluent API in Entity Framework

会有一股神秘感。 提交于 2019-12-02 06:04:53
问题 Using Entity Framework's API I keep coming across the following two ways to map many to many relationships? I have never used the second option... what is the difference? Option 1: modelBuilder.Entity<Student>() .HasMany( p => p.Lessons) .WithMany(); Option 2: modelBuilder.Entity<Student>() .HasMany(p => p.Lessons) .WithMany() .Map(m => { m.MapLeftKey("Id"); m.MapRightKey("Id"); m.ToTable("StudentAndLessons"); }); What exactly does MapLeftKey and MapRightKey do? When would you use it and what

How to read Custom Attributes using reflection set by Fluent API in EF 4.1

江枫思渺然 提交于 2019-12-02 05:39:45
I've managed to read custom attributes when I use data annotation. like following code. Object[] test = propertyInfo.GetCustomAttributes(typeof(KeyAttribute), true); But when I changed to use Fluent API. I couldn't read that attribute anymore. Any idea? Fluent API does not set attributes. Fluent API and Attributes tell EF how to build the model. These are two different ways to achieve the same thing. That is to build the Model. Edit If you need to retrieve the metadata such as primary keys you need to access the MetadataWorkspace . This article has the details. 来源: https://stackoverflow.com

Java inherited Fluent method return type in multiple level hierarchies

天涯浪子 提交于 2019-12-02 01:36:49
So following the solution described in Java - Inherited Fluent method return type to return incident class' type, not parent's . I want to extend it to multiple levels. The solution works in one level obviously. Here is compiled and runnable code (no dependencies): public enum X { ; static interface BaseFoo<T, S extends BaseFoo<T, S>> { S foo(); } static interface Foo<T> extends BaseFoo<T, Foo<T>> { void foo1(); } static abstract class AbstractFooBase<T, S extends BaseFoo<T, S>> implements BaseFoo<T, S> { abstract void internalFoo(); @Override public S foo() { internalFoo(); return (S)this; }

Fluent methods for data class in kotlin

回眸只為那壹抹淺笑 提交于 2019-12-01 13:25:44
We are familiar with fluent interfaces for calling methods in java and other programming languages. For eg: Picasso.with(this).load(url).into(imageView); This is made possible by setter methods what return object of desired type. public Picasso with(Context context) { this.context = context; return this; } public X load(String url) { this.url = url; return this; } public Y load(ImageView imageView) { this.imageView = imageView; return this; } I am trying to do the same with kotlin data classes but sadly I could not find a way to override the setter methods in which I could return the new

Fluent methods for data class in kotlin

时间秒杀一切 提交于 2019-12-01 10:40:59
问题 We are familiar with fluent interfaces for calling methods in java and other programming languages. For eg: Picasso.with(this).load(url).into(imageView); This is made possible by setter methods what return object of desired type. public Picasso with(Context context) { this.context = context; return this; } public X load(String url) { this.url = url; return this; } public Y load(ImageView imageView) { this.imageView = imageView; return this; } I am trying to do the same with kotlin data