[604] in java-interest

home help back first fref pref prev next nref lref last post

Re: Operator overloading

daemon@ATHENA.MIT.EDU (Francois BOUSSARD)
Thu Jul 6 13:21:43 1995

Date: Thu, 6 Jul 1995 12:11:44 +0200
From: Francois BOUSSARD <francois@coplanet.fr>
To: java-interest@java.Eng.Sun.COM

> >	From Francois Boussard (francois@coplanet.fr)
> >
> > 		- the Interface concept : good thing in place of virtual 
> > functions of C++.
> 
> 	From: johnm@medicus.com (John Mitchell)
>
> What do Java Interfaces have to do with C++ virtual functions?  Perhaps
> you are thinking of writing abstract virtual base classes in C++ to
> sorta mimic the Interface concept?
> 

Well, i think that such Java constructs :

	interface Movable {
		public void Move(int dx,int dy);
	}
	class Cubes implements Movable {
		public void Move(int dx, int dy){....}		
	}
	class Sphere implements Movable {
		public void Move(int dx, int dy){.....}
	}
	class Scheduler implement Movable {
		private Movable Tab=new Movable[10];
		public Register(Movable obj) {Tab[n]=obj;}
		public Move(int dx, int dy){for(...) Tab[n].Move(dx,dy)..}
	}
	class Appli {
		static private Cubes c;
		static private Sphere s;
		static private Scheduler sched;

		public static void main(..) {
			sched.Register(c);
			sched.Register(s);
			for(...) sched.Move(x,y);
		}
	}

Can replace the C++ virtual functions here :

	class Movable {
		virtual void Move(int dx, int dy)=0;
	};
	class Cubes : public Movable {	public:
		virtual void Move(int dx,int dy){..}
	};
	class Spheres : public Movable { public:
		virtual void Move(int dx, int dy){...}
	};
	class Scheduler implement Movable {
		Movable *Tab[10];
		public Register(Movable *obj) {Tab[n]=obj;}
		public Move(int dx, int dy){for(...) Tab[n]->Move(dx,dy)..}
	}
	Cubes c;
	Sphere s;
	Scheduler sched;

	void main(..) {
		sched.Register(c);
		sched.Register(s);
		for(...) sched.Move(x,y);
	}
	
	
> 
> > It's provides the concept of virtuality by explicit encapsulation of what is
> > virtual and implemented : realy prety thing .
> 
> It's the separation of interface inheritance from implementation 
> inheritance.  In doing so Java allows for multiple interface inheritance
> but only single implementation inheritance.
> 

	I agree.

> Take care,
> 	John
> 

	Ok, sorry for my mistakes, I spend a long time to read-back my text and 
correct my faults, but it's hard to write perfectly (:_:).

> P.S.	Just my personal opinions.
> 

  P.S.  Exactly the same !

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post