Those days I’m looking a new job related to Java and Flex… Seems that this is a popular interview question, I event didn’t encounter it in the ACE. But I was asked more than 3 times.
Talk about overloading in OOPS:
Overloading is between the methods with the same name, If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but signatures that are not override-equivalent, then the method name is said to be overloaded.
ActionScript 3 support overriding, But why it is not support overloading?
It’s a good question, and can be the answer of what’s the difference between Java and Flex?
Based on the Standard ECMA-262 (ECMAScript Language Specification), Action Script does not implement the overloading. and every method in the class is a Function object(property)
Since AS doesn’t support overloading, what can you do to implement the overloading?
As I known, Basically there are three way to handle the overload requirement:
1. Using optional parameters, such as:
getUser(userID:int = –1, userName: String = null):User {..}
2. Using rich parameters:
getUser(…args):User{
if(args.length == 0) {
return null;
}else if (args.length…)….
}
3. Using Object as the parameters, like:
getUser(arg: Object):User {
if(arg is String) {
return …. get user by the userName;
} else {
if (arg is int) {
return …get user by the userID;
}//end of if.
}
According those codes, you can see those methods all need very clear comments, and not easy for other to use them. in the comment we need to tell others the parameters type or sequence.
In fact, Since the AS does not support the overloading, and the comments need be very very clear, and usually, there will be two public methods: getUserByID(), getUserByName(), maybe a private or protected method using the above 3 ways to do the get user job.
Sometimes we use thread.sleep to let the thread stop running for a while in Java, but in Flex, we can’t control the thread, but sometimes we want to let the method sleeping, and here is what I’ll do:
public class SleepUtils { // Constructor public function SleepUtils() { } /** * Let the thread sleep. * @param ms Million seconds you want to sleep. * */ public static function startSleep(ms:Number):void { var timeBegin:Date = new Date(); trace("Sleep begin: " + timeBegin.toTimeString()); while((new Date()).getTime() - timeBegin.getTime() < ms) { } trace("Sleep end: " + new Date().toTimeString()); } } // End of class
What’s the difference ? Here is the test codes:
We will create a button in a Group, and listen the button click event(MouseEvent.Click):
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void { // Create button and container var hbox:HGroup = new HGroup(); var button:Button = new Button(); button.label = "Button"; // Add Eventer litener button.addEventListener(MouseEvent.CLICK, onButtonClick1); button.addEventListener(MouseEvent.CLICK, onButtonClick2); hbox.addEventListener(MouseEvent.CLICK, onButtonClick3); hbox.addElement(button); addElement(hbox); } // Button click handler 1 private function onButtonClick1(e:MouseEvent):void { e.stopImmediatePropagation(); // or e.stopPropagation(); trace("Handler 1"); } // Button click handler 2 private function onButtonClick2(e:MouseEvent):void { trace("Handler 2"); } // Button click handler 3 listened by hbox private function onButtonClick3(e:MouseEvent):void { trace("Handler 3"); }
Here is the difference:
when use stop propagation in the handler 1st, the trace is:
Handler 1
Handler 2
but when use stopImmediatePropagation(), the trace is:
Handler 1
That’s pretty easy to find the differences:
“The stopImmediatePropagation() method also prevents the Event objects from moving on to the next node, but it does not allow any other event listeners on the current node to execute.” (Adobe livedocs)
满共50道题, 大概想起来45道, 人上了年纪后脑子就不灵光了, 只能大致描述下题目主要内容, 能用中文描述的用了中文, 搞不定的保持英文. 有些选项也记得不全, 仅供复习参考.
已整理成PDF, 下载页面: http://dl.dbank.com/c0ygcsiqso
Update:
又想起来一道Air题目:
在Mac上如何删除Air程序: 大致选项:
1. 运行Uninstall Script; 2. 删除文件; 3. 运行安装包; 4. 删除快捷方式一类的…具体项目及不太清楚了, 5选2;
首先了解一下Adboe 认证体系:
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.