fluent-interface

Designing a fluent Javascript interface to abstract away the asynchronous nature of AJAX

百般思念 提交于 2019-11-26 15:36:07
问题 How would I design an API to hide the asynchronous nature of AJAX and HTTP requests, or basically delay it to provide a fluent interface. To show an example from Twitter's new Anywhere API: // get @ded's first 20 statuses, filter only the tweets that // mention photography, and render each into an HTML element T.User.find('ded').timeline().first(20).filter(filterer).each(function(status) { $('div#tweets').append('<p>' + status.text + '</p>'); }); function filterer(status) { return status.text

No type inference with generic extension method

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 15:29:37
I have the following method: public static TEventInvocatorParameters Until <TEventInvocatorParameters, TEventArgs>(this TEventInvocatorParameters p, Func<TEventArgs, bool> breakCond) where TEventInvocatorParameters : EventInvocatorParameters<TEventArgs> where TEventArgs : EventArgs { p.BreakCondition = breakCond; return p; } And this class public class EventInvocatorParameters<T> where T : EventArgs { public Func<T, bool> BreakCondition { get; set; } // Other properties used below omitted for brevity. } Now, I have the following problems: This extension method shows on all types, even string .

Entity Framework Code First Fluent Api: Adding Indexes to columns

纵然是瞬间 提交于 2019-11-26 12:50:06
问题 I\'m running EF 4.2 CF and want to create indexes on certain columns in my POCO objects. As an example lets say we have this employee class: public class Employee { public int EmployeeID { get; set; } public string EmployeeCode { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime HireDate { get; set; } } We often do searches for employees by their EmployeeCode and since there are a lot of employees it would be nice to have that indexed for

Fluent interfaces and inheritance in C#

a 夏天 提交于 2019-11-26 12:04:16
问题 I\'ll show a problem by example. There is a base class with fluent interface: class FluentPerson { private string _FirstName = String.Empty; private string _LastName = String.Empty; public FluentPerson WithFirstName(string firstName) { _FirstName = firstName; return this; } public FluentPerson WithLastName(string lastName) { _LastName = lastName; return this; } public override string ToString() { return String.Format(\"First name: {0} last name: {1}\", _FirstName, _LastName); } } and a child

Method chaining - why is it a good practice, or not?

拟墨画扇 提交于 2019-11-26 11:31:09
Method chaining is the practice of object methods returning the object itself in order for the result to be called for another method. Like this: participant.addSchedule(events[1]).addSchedule(events[2]).setStatus('attending').save() This seems to be considered a good practice, since it produces readable code, or a "fluent interface". However, to me it instead seems to break the object calling notation implied by the object orientation itself - the resulting code does not represent performing actions to the result of a previous method, which is how object oriented code is generally expected to

Fluent Interfaces - Method Chaining

≡放荡痞女 提交于 2019-11-26 10:18:11
问题 Method chaining is the only way i know to build fluent interfaces. Here\'s an example in C#: John john = new JohnBuilder() .AddSmartCode(\"c#\") .WithfluentInterface(\"Please\") .ButHow(\"Dunno\"); Assert.IsNotNull(john); [Test] public void Should_Assign_Due_Date_With_7DayTermsVia_Invoice_Builder() { DateTime now = DateTime.Now; IInvoice invoice = new InvoiceBuilder() .IssuedOn(now) .WithInvoiceNumber(40) .WithPaymentTerms(PaymentTerms.SevenDays) .Generate(); Assert.IsTrue(invoice.DateDue ==

No type inference with generic extension method

血红的双手。 提交于 2019-11-26 04:27:10
问题 I have the following method: public static TEventInvocatorParameters Until <TEventInvocatorParameters, TEventArgs>(this TEventInvocatorParameters p, Func<TEventArgs, bool> breakCond) where TEventInvocatorParameters : EventInvocatorParameters<TEventArgs> where TEventArgs : EventArgs { p.BreakCondition = breakCond; return p; } And this class public class EventInvocatorParameters<T> where T : EventArgs { public Func<T, bool> BreakCondition { get; set; } // Other properties used below omitted for

Can you monkey patch methods on core types in Python?

丶灬走出姿态 提交于 2019-11-26 00:58:54
问题 Ruby can add methods to the Number class and other core types to get effects like this: 1.should_equal(1) But it seems like Python cannot do this. Is this true? And if so, why? Does it have something to do with the fact that type can\'t be modified? Update: Rather than talking about different definitions of monkey patching, I would like to just focus on the example above. I have already concluded that it cannot be done as a few of you have answered. But I would like a more detailed

Can you monkey patch methods on core types in Python?

梦想与她 提交于 2019-11-25 21:37:17
Ruby can add methods to the Number class and other core types to get effects like this: 1.should_equal(1) But it seems like Python cannot do this. Is this true? And if so, why? Does it have something to do with the fact that type can't be modified? Update: Rather than talking about different definitions of monkey patching, I would like to just focus on the example above. I have already concluded that it cannot be done as a few of you have answered. But I would like a more detailed explanation of why it cannot be done, and maybe what feature, if available in Python, would allow this. To answer