473,508 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Own implementation of an interface

Hi

Firstly i'd like to thank you for reading this and offer my appreciation
for replies in advance.

I've recently been writing a program which implements a user-defined API
(Robocode to be exact). I, however, need to create my own implementation
of an interface in order to perform some arbitary function.

My question is, how would i go about creating my own instance of this
interface so that the API utilises my methods instead of the blank,
skeleton ones already provided?

Is it simply Public interface myInterface extends APIInterfaceCLassNAMe?

or is there some other method?

As far as java goes i've always been a little hazey around the concept
of interfaces, thus my confusion.
thanks

Gabriel
Oct 27 '06 #1
4 2777
An interface is simply a definition of the way a class is expected to
"act". It's a collection of definition of methods each of which must be
implemented for a class to be said "implementing" that interface.

To create an implementation of an interface either you can write it
"implements" that interface and implement every single interface method,
or you can write it extends another class that implements the interface
and override those methods that must have custom implementation/behavior.

Luca.

gabriel ha scritto:
Hi

Firstly i'd like to thank you for reading this and offer my appreciation
for replies in advance.

I've recently been writing a program which implements a user-defined API
(Robocode to be exact). I, however, need to create my own implementation
of an interface in order to perform some arbitary function.

My question is, how would i go about creating my own instance of this
interface so that the API utilises my methods instead of the blank,
skeleton ones already provided?

Is it simply Public interface myInterface extends APIInterfaceCLassNAMe?

or is there some other method?

As far as java goes i've always been a little hazey around the concept
of interfaces, thus my confusion.
thanks

Gabriel
Oct 27 '06 #2
gabriel <pe*******@ether.netwrote:
>My question is, how would i go about creating my own instance of this
interface so that the API utilises my methods instead of the blank,
skeleton ones already provided?
Is it simply Public interface myInterface extends APIInterfaceCLassNAMe?
You probably want public myClass implements APIInterfaceName. And provide
actual implementations of all the methods. If you write an interface, you can
declare methods but not actually implement any of them.
>or is there some other method?
As far as java goes i've always been a little hazey around the concept
of interfaces, thus my confusion.
An interface is just a pure abstract class, with a slightly different syntax
for creating the subclass - you implement it rather than extending it.

Many frameworks provide both an interface and a convenience base class that
partially implements it and lets you override just the part you want to change
(like Swing's Action interface and AbstractAction class - you can implement
Action or extend AbstractAction, depending on your needs).

I haven't played with Robocode much, but I thought it did this as well - you
extend Robot (or AdvancedRobot) and override the methods that get called at
various events.
--
Mark Rafn da***@dagon.net <http://www.dagon.net/>
Oct 29 '06 #3
Lew
gabriel <pe*******@ether.netwrote:
>My question is, how would i go about creating my own instance of this
interface so that the API utilises my methods instead of the blank,
skeleton ones already provided?
Mark Rafn wrote:
You probably want public myClass implements APIInterfaceName.
"public MyClass ..."

Class names should start with an upper-case letter.

- Lew
Oct 29 '06 #4
Lew wrote:
>gabriel <pe*******@ether.netwrote:
>>My question is, how would i go about creating my own instance of this
interface so that the API utilises my methods instead of the blank,
skeleton ones already provided?

Mark Rafn wrote:
>You probably want public myClass implements APIInterfaceName.

"public MyClass ..."

Class names should start with an upper-case letter.

- Lew
Starting class names with an upper-case letter, is a widely used (good)
convention. But I don't think it is required by the language.

The following code compiles and executes just fine.

public class sample
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
--
Prasad
Nov 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
1273
by: Jeff Bowman | last post by:
If there weren't a real strong reason for having it, Microsoft wouldn't have bothered with including Implementation in the language. But doggone it, I'll be darned if I can see what's so great...
9
4617
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
2
1703
by: IK | last post by:
Hello All, Please excuse me for posting this here, but I don't find any other group where I will get a proper answer. This is about clarifying the C++ part of COM. I understand that COM is a...
12
2757
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that...
3
6733
by: Juerg Staub | last post by:
Hi, I have implemented IInternetProtocol and IInternetProtocolRoot in my protocol handler. Whenever I try to register the instance with IInternetSession::RegisterNameSpace, I receive a...
175
8645
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
5
2431
by: Keith Patrick | last post by:
Could someone tell me if it's possible (and if so, how) to call an explicitly-implemented interface method from a subclass? I have a class in which I have to explicity implement some methods, but...
2
2503
by: COLIN JACK | last post by:
Hi All, I've got a situation where I'm implementing an interface (BaseInterface in example below) and I want to use explicity interface implementation of an event so that I can add type safety. ...
4
3332
by: Rubbrecht Philippe | last post by:
Hi there, I would like to develop an interface that when implemented in a class requires a number of shared properties or methods to be available. It seems a Shared Member can not be used as...
20
6044
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.