Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

My own API  RSS feed

 
Adewale Adebusoye
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, im tryin to create my own API for an assignment. the API is meant to provide facilities to create ordered sets and to perform some operations which i will define below.
The library is meant to be called GenericSet.

And it sholod implement some functions like

GenericSet initialize which returns the empty set

GenericSet insert(GenericSet z, item i) adds element i to the GenericSet and returns a new set.

the functions are meant to be static

ok now for the questions..im a bit confused as to how im gonna implement this.

My idea is to write a class GenericSet..then mebbe have an array or a list where i can hold all the items to be stored, then for each of the methods like initialize and insert()..i simply work with the array(like inserting the elements into it)..then i return a this object; this referring to the current GenericSet object.

But the static methods are confusing me... can someone someone tell me if my ideas are right? and will using static methods change the way i have to implement this?

Thanks a lot
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know if you are allowed to do this, but I think the easiest would be to just extend one of the lists or sets in the Collections Framework which is closest to your required functionality and then just add the extra functionality you need.
 
Adewale Adebusoye
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah im allowed to do that.
thanks..any other suggestions? do you think my initial idea works?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you use static methods? You're designing this as if it's C code, not Java code. Instead of a static "initialize" that returns an empty set, you'd want to use a constructor. Instead of insert(GenericSet, item), you should have a non-static insert(item).
 
Adewale Adebusoye
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah i know that using static methods dosent cut it at all..but im constrained by the assignment rules which state that the methods all have to be static.

Please can anyone give me a link to any samplecode where either List, ArrayList or Vector was extended, with added functionality?

Thanks
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably wont get any points if you tell your teacher that the assignment ... ahh uhh... is a bit ahhh silly.... ?

pascal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!