Atlas使用接口

 
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
 
< head >
  
< title > interface.html title >
  
< meta  http-equiv ="keywords"  content ="keyword1,keyword2,keyword3" >
  
< meta  http-equiv ="description"  content ="this is my page" >
  
< meta  http-equiv ="content-type"  content ="text/html; charset=UTF-8" >
  
< script  type ="text/javascript"  src ="Atlas.js" > script >
 
head >
 
< script  type ="text/javascript" >
    Type.registerNamespace(
"Demo.Animals");
Demo.Animals.Ipet 
= function(){
 
this.getFriendly = Function.abstractMethod();
}

Demo.Animals.Ipet.registerInterface(
'Demo.Animals.Ipet');
Demo.Animals.Animal 
= function(name){
 
var _name = name;
 
this.getName = function(){
  
return _name;
 }

}

Demo.Animals.Animal.registerAbstractClass(
'Demo.Animals.Animal');
Demo.Animals.Animal.prototype.toStringCustom 
= function(){
 
return this.getName();
}

Demo.Animals.Animal.prototype.speak
=Function.abstractMethod;
Demo.Animals.Pet
=function(name,friendlyName){
 Demo.Animals.Pet.registerAbstractClass(
'Demo.Animals.Pet',Demo.Animals.Animal,Demo.Animals.Ipet);
}

Demo.Animals.Cat 
= function(friendlyName){
Demo.Animals.Cat.initializeBase(
this, ['Cat', friendlyName]);
}

Demo.Animals.Cat.registerClass(
'Demo.Animals.Cat', Demo.Animals.Pet);
Demo.Animals.Cat.prototype.speak 
= function() {
    alert(
'meow');
}

Demo.Animals.Cat.prototype.toStringCustom 
= function() {
    
return 'Pet ' + Demo.Animals.Cat.callBaseMethod(this'toStringCustom');
}

Demo.Animals.Felix 
= function() {
    Demo.Animals.Felix.initializeBase(
this, ['Felix']);
}

Demo.Animals.Felix.registerClass(
'Demo.Animals.Felix', Demo.Animals.Cat);
Demo.Animals.Felix.prototype.toStringCustom 
= function() {
    
return Demo.Animals.Felix.callBaseMethod(this'toStringCustom'+ '  its Felix!';
}


Demo.Animals.Dog 
= function(friendlyName) {
    Demo.Animals.Dog.initializeBase(
this, ['Dog', friendlyName]);
}

Demo.Animals.Dog.registerClass(
'Demo.Animals.Dog', Demo.Animals.Pet);
Demo.Animals.Dog.prototype.speak 
= function() {
    alert(
'woof');
}


Demo.Animals.Tiger 
= function() {
    Demo.Animals.Tiger.initializeBase(
this, ['Tiger']);
}

Demo.Animals.Tiger.registerClass(
'Demo.Animals.Tiger', Demo.Animals.Animal);
Demo.Animals.Tiger.prototype.speak 
= function() {
    alert(
'grrr');
}

    
script >
 
< body >
  This is my HTML page.
  
< br >
 
body >
html >
但是奇怪的是
a =new  Demo.Animals.Animal("cat");
alert(a.getName());
居然不会出错,也就是说虚类是可以实例化的。

你可能感兴趣的:(Atlas使用接口)