fluent-interface

Fluent API with inheritance and generics

走远了吗. 提交于 2019-12-17 18:25:47
问题 I'm writing a fluent API to configure and instantiate a series of "message" objects. I have a hierarchy of message types. To be able to access method of subclasses when using the fluent API, I used generics to parametrize the subclasses and make all fluent methods (that start with "with") return the generic type. Note that I omitted most of the body of the fluent method; a lot of configuration goes on in them. public abstract class Message<T extends Message<T>> { protected Message() { }

Thread safety of a fluent like class using clone() and non final fields

主宰稳场 提交于 2019-12-13 15:51:25
问题 This fluent like class is not strictly immutable because the fields are not final, but is it thread safe, and why? The thread safety issue I'm concerned with is not the race condition, but the visibility of the variables. I know there is a workaround using final variables and a constructor instead of clone() + assignment. I just want to know if this example is a viable alternative. public class IsItSafe implements Cloneable { private int foo; private int bar; public IsItSafe foo(int foo) {

Entity Framework Code First - Foreign Key to non primary key field

限于喜欢 提交于 2019-12-13 12:08:07
问题 I have two tables that look like this: dbo.ReviewType ReviewTypeId INT PRIMARY KEY ShortName CHAR(1) - Unique Index Description dbo.Review ReviewId INT PRIMARY KEY ReviewType_ShortName CHAR(1) - FK to ReviewType ... A Review always has a ReviewType. A ReviewType can be associated with many reviews. I'm having trouble mapping this in Entity Framework using the Code First Fluent API. It seems like it does not like me using a foreign key that doesn't map to the Primary Key. I'm using a foreign

Entity Framework - Inheritance - Zero to one Relationship to child object, how to map? (Fluent API)

邮差的信 提交于 2019-12-13 07:10:40
问题 I have a Inheritance Hierarchy where Action is parent of ActionCompleted and ActionCancelled. Order class has a zero to one ActionCompleted and ActionCancelled. I have tried TPH and TPT (even tried edmx) but unable to get Entity to understand this relationship between Order and child actions, please suggest how do I map? //Classes public class Order { public int OrderId { get; set; } public string Name { get; set; } public ActionCompleted ACO { get; set; } public ActionCancelled ACA { get;

Fluent API and Method-Chaining Style Usage

时光怂恿深爱的人放手 提交于 2019-12-12 18:19:48
问题 When programming against a fluent API or just using method-chaining, I've seen the style mostly like this: var obj = objectFactory.CreateObject() .SetObjectParameter(paramName, value) .SetObjectParameter(paramName, value) .DoSomeTransformation(); What is the reasoning behind putting the dot at the beginning of the line instead of the end of the line like this: var obj = objectFactory.CreateObject(). SetObjectParameter(paramName, value). SetObjectParameter(paramName, value).

Is jQuery method chaining an example of fluent programming?

…衆ロ難τιáo~ 提交于 2019-12-12 11:53:03
问题 I'm somewhat new to JavaScript/jQuery, but when I saw examples of method chaining it struck me as instantly familiar. Other interfaces like LINQ do something similar where the return type of a set of methods is the same as the type they operate on (TweetSharp does something very similar). Is this an example of fluent programming? Much of what I read about jQuery says that other libraries have "borrowed" this idea of method chaining - did the idea originate with jQuery? 回答1: jQuery indeed

Fluent interface with inheritance in Delphi

自作多情 提交于 2019-12-12 11:15:16
问题 I have following fluent interface declaration and class that implements that interface: type IDocWriter = interface ['{8CB5799A-14B1-4287-92FD-41561B237560}'] function Open: IDocWriter; function Close: IDocWriter; function Add(const s: string): IDocWriter; function SaveToStream(Stream: TStream): IDocWriter; end; TDocWriter = class(TInterfacedObject, IDocWriter) public function Open: IDocWriter; function Close: IDocWriter; function Add(const s: string): IDocWriter; function SaveToStream(Stream

Fluent Interfaces Implementation

旧巷老猫 提交于 2019-12-12 09:49:32
问题 In order to make my code more organized i have decided to use fluent interfaces; However by reading the available tutorials i have found many ways to implement such fluency, among them i found a topic who says that to create Fluent Interface we should make use of Interfaces , but he did not provided any good details in order to achieve it. Here is how i implement Fluent API Code public class Person { public string Name { get; private set; } public int Age { get; private set; } public static

Effects of method chaining

痴心易碎 提交于 2019-12-12 08:47:33
问题 I know the benefits of chaining within PHP but lets say we have this following situation $Mail = new MailClass("mail") ->SetFrom("X") ->SetTo("X") ->SetSubject("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->Send(); Are there any issues with returning and reusing the object over and over again, issues such as speed or failure to follow best Practises Also a good read on this if your new to Fluent-Interface's:

IronPython DSL casting constants to C# types

不想你离开。 提交于 2019-12-12 06:30:09
问题 I am implementing a DSL in IronPython. Suppose I have a value hierachy implemented in C# to be used in iron python: public abstract Value { } public abstract DoubleValue : Value { // Constructors... public double magnitude; // Arithmetic operators overloaded... } public abstract FractionValue : Value { // Constructors.... public int numerator; public int denominator; // Arithmetic operators overloaded... } Due to the operator overloading in C#, i can do this in Python: # a, b are of type