spacer
Yehuda Shiran June 29, 2002
Implementing the Integer Version of the ICopyObj Interface
Tips: June 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
One of the ways to support polymorphism is to define an interface that accepts an object of the type Object, and implement it in classes that support actual types as integer, double, and user-defined classes. The code below defines the interface ICopyObj which is implemented by the class CopyInt. This class defines two methods: the constructor CopyInt() and the interface function Copy(). The main program creates two variables, h1 and h2. The variable h1 is generated through the CopyInt() constructor. The variable h2 is generated through the Copy() operator. We print both variables at the end. Here is the code listing:

  // compile with: jsc interface.js

  interface ICopyObj {
    function Copy() : Object;
  }

  class CopyInt implements ICopyObj {
    public var i : int;
    public function CopyInt(i : int) {
      this.i = i;
    }
    public function Copy() : Object {
      return new CopyInt(i)
    }
  }

  var h1 : CopyInt = new CopyInt(8);
  var h2 : CopyInt = h1.Copy();
  print("Original: " + h1.i + " Copy: " + h2.i);
And here is the Command Prompt window, showing the code again (interface.js), the jsc compiler's log messages, and the output of interface.exe:

To learn more about JScript .NET, go to Column 111, JScript .NET, Part V: Polymorphism.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends