multilline use of object methods - multimethod

I have a question that's nagging me.
Is it possible to use multiple methods of an
instance , without writing the name. I dont
mean static methods.
Language : java
For example: object name bibo of class manager
the class has three methods
- fire
- hiring
- raise
And what i want is like this:
bibo.fire();
.hiring();
.raise();
I'm asking cause I saw this in another project, but cant recall how it was done or what project it was.

Related

Defining and implementing interfaces in R

I'm interested in defining and inheriting from interfaces in R. By interface, I mean OOP interfaces. I know R supports class extension. This link http://adv-r.had.co.nz/OO-essentials.html gives an example of extending a reference class in R. It defines a NoOverdraftAccount reference class that extends an Account reference class.
Instead of extending the Account reference class, I'd like to be able to define an account interface, IAccount. I would like I'd like NoOverDraftAccount to implement IAccount, such that:
NoOverDraftAccount must implement all methods in IAccount.
NoOverDraftAccount cannot declare any new public methods not already declared in IAccount.
NoOverDraftAccountcan declare private methods and properties.
What's the best way to achieve this?
The closest I've come to an answer was from the question Multiple inheritance for R6 classes. But, the question wasn't focused on interfaces.
Thanks for your time.
I don't think "declarations" make much sense in an interpreted language like R. As there's no compile step there's no way to test if something actually conforms to a declared interface without running a function on the class, something like does_class_follow(class,interface), at some point.
So I think you have to start from scratch - you need to define an interface specification class and write the does_class_follow function.
My first thought was that a class would have to know what interface(s) it conformed to so that the test could introspect this, but perhaps that's wrong and you should have a file of interface definitions and pseudo-declarations that tested everything.
For example, have some file interfaces.R that looks like:
IAccount = Interface(
public = list("deposit","withdraw")
)
Implements(Account, IAccount)
Implements(Account, NoOverDraftAccount)
Then when the package is loaded those Implements functions would run and test the classes against that specification of what an Account interface is. Whether its better to test at load time or to put these sort of things in the ./test/ folder and test them at test time using test_that or another test system is a question...
As you may be aware you'll have to implement this separately for all the OO systems in R that you want to use - S3, S4, R5, ReferenceClasses, R6, proto, R.oo and all the other ones I've forgotten...

Getting a static instance of a class (singleton) by using getDefinitionByName

I have a ManagerClass with a Singleton implementation inside, I get the instance by calling ManagerClass.getInstance().
Can I get that same instance by just having the class name as a string?
I have tried something like:
var theInstance:* = getDefinitionByName("ManagerClass").getInstance as Class;
theInstance.doTrace(); // I get a 1009 error here
well - im dealing with singletons because the application that I'm working on is written in cairngorm, and a whole bunch of things have to be singletons in it.
in regards to why I need to "pass the class names" instead of hardcoding them - is for exact that reason - I don't want to hardcode anything in. this application is 5 years in developement, and now would not be good time to switch it to RobotLegs and such.
haha - yea, you're right - i forgot the () after getInstance. Must be the lack of sleep... Now it works!!!!
Sure why not make a Singleton manager (similar to the Flex core mx.core.Singleton class) that registers these classes and handles if they're null.
Similar to here :
http://segfaultlabs.com/devlogs/overriding-default-flexair-mxmanagers-implementations

Utility class or Common class in asp.net

Do anyone knows about the class which has the common function which we generally use while developing web application. I have no idea what you may call it, it may be the utility class or common function class. Just for reference, this class can have some common function like:
Generate Random number
Get the file path
Get the concatinated string
To check the string null or empty
Find controls
The idea is to have the collection of function which we generally use while developing asp.net application.
No idea what you are really asking, but there already are ready-made methods for the tasks you write in various library classes:
Random.Next() or RNGCryptoServiceProvider.GetBytes()
Path.GetDirectoryName()
String.Concat() or simply x + y
String.IsNullOrEmpty()
Control.FindControl()
Gotta love the intarwebs - An endless stream of people eager to criticize your style while completely failing to address the obvious "toy" question. ;)
Chris, you want to inherit all your individual page classes from a common base class, which itself inherits from Page. That will let you put all your shared functionality in a single place, without needing to duplicate it in every page.
In your example it looks like utility class - it is set of static functions.
But I think that you should group it in few different classes rather than put all methods in one class - you shouldn't mix UI functions(6) with string functions(3,4), IO functions (2) and math(1).
As Mormegil said - those functions exists in framework, but if you want to create your own implementations then I think that for part of your function the best solution is to create extension method.

UDK "Error, Accessing a member of _'s within class through a context expression requires explicit 'Outer'"

I get the following error in the UDK Frontend when I try to make my project:
C:\UDK\UDK-2010-03\Development\Src\FixIt\Classes\ZInteraction.uc(58) : Error, Accessing a member of GameUISceneClient's within class through a context expression requires explicit 'Outer'
The class ZInteraction extends Interaction.
Line 58 is: GetSceneClient().ConsoleCommand("KEYNAME"#Key);
What is the problem here? I am still investigating and I will update as I find out more.
edit: Tried fixing the line up as class'UIRoot'.static.GetSceneClient().ConsoleCommand("KEYNAME"#Key); - no change.
Found it!
From a forum post, Scripting Changes from UT3:
When accessing a member of a within class' container class, you now have to use the special Outer member variable. This presumably helps deal with name clashes.
I had to change the code to the following:
GetSceneClient().Outer.Outer.ConsoleCommand("KEYNAME"#Key);
Depending on what function is giving you this error, you will need one or more sets of Outer.. You can research to find out how many layers deep you are, or you can just add one at a time until the code compiles. I chose the latter, because it's hard enough already to navigate this UnrealScript. :)

Subclassing a private (support) class in AVM2

I am developing a dynamic mocking framework for Flex/AS3 and am having trouble with private/support types (ie. those declared outside the package {} in a class file).
In my ABC "file", I am declaring the instance with the PROTECTED_NAMESPACE class flag and with a PRIVATE_NS multiname. I have also experimented with giving it the same namespace as the class it is subclassing (eg. PRIVATE_NS("ContainerClass.as$123")).
No matter what I do, I always get the following error after loadBytes:
VerifyError: Error #1014: Class ContainerClass.as$123::PrivateClass could not be found.
I have experimented with loading the generated bytecode into the same ApplicationDomain as the private class (I use a child domain by default). I even tried registering a class alias before the load (though that was a bit of a stretch).
Am I forgetting anything or is it simply a restriction of the AVM?
Please note that I am fully aware that this is illegal in ActionScript 3.0, I am looking for whether this is actually possible in the AVM.
Edit: For those interested in the work so far, the project is asmock and is on sourceforge.
I'm no expert with ABC files but I just don't think this is possible in the AVM2. I did several tests a while ago with the AS3 Eval lib and they all failed.
Related to dynamic mocking, I have filed an issue in Adobe bugbase, asking for a dynamic proxy mechanism: http://bugs.adobe.com/jira/browse/ASC-3136
I'm not sure what you mean by PRIVATE_NS("ContainerClass.as$123"), My reading of avm2overview.pdf 4.4.1 is that private namespaces are not permitted to have a name, hence that the "<class name>$<number>" namespace in debug output is generated for your convenience. I would assume that would mean you would have to hack your abc into the same abc tag in the source swf to access the namespace constant index (and that sounds too much like hard work to me!)
I haven't actually managed to generate a loading swf, though, so take this with a grain of salt.
Having gone back to look at this problem in ernest, I can definitively answer this question: private classes can only be referenced from the LoaderContext that loaded them
I have been able to add support for private interfaces by reproducing the interface in the loaded ABC 'file', but it cannot be coerced/cast back to the original private interface.
This is still useful for my requirements, as a private interface can be used to combine multiple interfaces.

Resources