delegation

Is there a way to emulate PHP5's __call() magic method in PHP4?

大憨熊 提交于 2019-12-11 03:54:18
问题 PHP5 has a "magic method" __call() that can be defined on any class that is invoked when an undefined method is called -- it is roughly equivalent to Ruby's method_missing or Perl's AUTOLOAD . Is it possible to do something like this in older versions of PHP? 回答1: The most important bit that I was missing was that __call exists in PHP4, but you must enable it on a per-class basis by calling overload() , as seen in php docs here . Unfortunately, the __call() function signatures are different

Cant call delegate method from my protocol class

蓝咒 提交于 2019-12-11 02:44:55
问题 I have a protocol in one class: @protocol DataStorageManager - (void) saveFile; @end @interface DataManager : NSObject { id <DataStorageManager> delegate; } @property (nonatomic, assign) id<DataStorageManager> delegate; //methods @end and its implementation: @implementation DataManager @synthesize delegate; @end and I have another class which is the adapter between the first and the third one: #import "DataManager.h" #import "DataPlistManager.h" @interface DataAdapter : NSObject

delegating into private parts

为君一笑 提交于 2019-12-10 12:34:33
问题 Sometimes, C++'s notion of privacy just baffles me :-) class Foo { struct Bar; Bar* p; public: Bar* operator->() const { return p; } }; struct Foo::Bar { void baz() { std::cout << "inside baz\n"; } }; int main() { Foo::Bar b; // error: 'struct Foo::Bar' is private within this context Foo f; f->baz(); // fine } Since Foo::Bar is private , I cannot declare b in main . Yet I can call methods from Foo::Bar just fine. Why the hell is this allowed? Was that an accident or by design? Oh wait, it

Java: Delegation Pattern and Protected Methods

大兔子大兔子 提交于 2019-12-09 18:21:28
问题 I have been using delegation pattern to wrap an object created by a factory in a 3rd party library. Recently, the library added a protected method in the base class and my wrapper class doesn't work any longer. Does anyone have a good solution without resorting to reflection? This is in 3rd party library and in their package, public class Base { public void foo(); protected void bar(); // Newly added } This is in my own package, public class MyWrapper extends Base { private Base delegate;

Emulating membership-test in Python: delegating __contains__ to contained-object correctly

南楼画角 提交于 2019-12-09 12:44:19
问题 I am used to that Python allows some neat tricks to delegate functionality to other objects. One example is delegation to contained objects. But it seams, that I don't have luck, when I want to delegate __contains __: class A(object): def __init__(self): self.mydict = {} self.__contains__ = self.mydict.__contains__ a = A() 1 in a I get: Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument of type 'A' is not iterable What I am making wrong? When I call a._

How to convert Delegate to Observable RxSwift?

…衆ロ難τιáo~ 提交于 2019-12-09 07:38:18
问题 I have delegate methods, which I need to wrap by Delegate Proxy in RxSwift. I have done it using Bond and Reactive, but here, in RxSwift, I am not able to find the proper way to convert it. Follow is Protocols import UIKit /** A protocol for the delegate of a `DetailInputTextField`. */ @objc public protocol CardInfoTextFieldDelegate { /** Called whenever valid information was entered into `textField`. - parameter textField: The text field whose information was updated and is valid. -

How can a method's Javadoc be copied into other method's Javadoc?

旧巷老猫 提交于 2019-12-09 00:25:39
问题 I know that there is @inheritDoc , but it's only for methods which override others. I have several classes with many delegate methods (which do not override others). Can their Javadoc be "inherited" (more exactly: copied)? /** here I need the copy of wrappedMethod's Javadoc */ public void delegateMethod(Object param){ innerSomething.wrappedMethod(param); } 回答1: A @link or @see tag would be appropriate here. If you're wrapping the method, it must provide distinctive behavior which makes it

How does UITableViewCell communicate with its UITableView?

不想你离开。 提交于 2019-12-08 21:43:19
问题 I am currently creating a custom grid view, which means that I am creating a class that has a lot in common with UITableView . One of the things that I want to get right is the communication of the cells and the grid view. I was therefore wondering how a table view cell talks to its table view. For example, how does the cell notify the table view that its delete button was tapped and the cell needs to be removed from the table view? There are several possible scenarios, but I am not sure

Pattern for delegation to sub-component

前提是你 提交于 2019-12-07 20:16:43
问题 In the product I am working, one of very basic scenario is serialization of classes. Typically a class to be serialized calls serialization on its sub-component e.g. if there is a class s.t. class A{B;C;D;} then A.Pack will call pack function on B,C,D. Since there are many such classes, same pattern of code has to be duplicated over and over again. Is it possible to encapsulate this behavior in a pattern (possibly using templates and inheritance) 回答1: The usual way of making a template do

Impersonation and delegation (with SQL Server) in ASP.NET

♀尐吖头ヾ 提交于 2019-12-07 11:32:21
问题 I've written a simple ASP.NET application that works as a frontend for a simple MSSQL database. The application is accessible over the Internet. There are two physical servers involved: a WS2008R2 Active Directory domain controller which is also running MSQL Server 2008 R2, and another server, the webserver (WS2008R2/IIS7.5) where my application resides. The Application Pool for my application "FooPool" has its own AD User identity it runs under "FooUser". FooUser does not have any permission