Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 554359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:04+00:00 2026-05-13T11:42:04+00:00

Ok so I am writing an open source library. A section of this library

  • 0

Ok so I am writing an open source library. A section of this library deals with moving an entity in a two and three dimensional space so it will have functions that manipulate the rotation, position etc.

Now ideally I would like my library to work well with other libraries, in particular things like Papervision3D and other Flash 3D engines, but not forgotting basic image objects like a Sprite or Movieclip.

So this is my quandary. The functions that will manipulate the entity will also need to modify the values of the underlying model data (so either a Sprite, Papervision object etc). What is the best way to make my library flexible so that it can support multiple data models. Performance is also important aspect too.

Currently I am thinking of something like this:

  //this is the public function that I expose in my library
  public function rotate(val:Number,func:Function,objData:*):void
  {
 func(val,objData);
  }

  //example of a function that could be passed in
  //this one will rotate a MovieClip
  private function modelFunction1(rot:Number,objData:*):void
  {
 var myMov:MovieClip  = objData as MovieClip;
 myMov.rotation = rot;
  }

  //second example of a function that could be pass in
  //this one will rotate a point
  private function modelFunction2(rot:Number,objData:*):void
  {
     //yes I know this piece of code makes no sense :P
     var p:Point = objData as Point;
  p.x = Math.cos(rot);
     p.y = Math.sin(rot);
  }

so then it could be used like:

rotate(4,modelFunction2,myPoint)

//or

rotate(4,modelFunction1,mySprite);

I should add that in reality I, as the client code, won’t be able to directly call the rotate function. Instead the rotate function that I want to pass in would need to be stored somewhere as a class member and then be called by the rotate function. Its just less code for me to write it out like above.

This to me seems quite flexible although the performance implications of casting and passing functions concerns me (but might be ok). Can anyone else suggest an alternative or is what I have the most logical solution. Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:42:05+00:00Added an answer on May 13, 2026 at 11:42 am

    I suggest the adapter pattern.

    In your case you could define interfaces which offer type safe definitions for what your library expects instead of having function arguments.
    then you need to write adapter classes which implement your librarys interfaces and wrap for instance a papervision object and delegate the function calls to your interface methods to the papervision object.

    interface IRotatatable {
       function rotate(deg : Number) : void
    }
    
    class YourLibraryClass {
    
        public function rotate(r : IRotatatable, val : Number):void {
           r.rotate(val)
        } 
    }
    
    
    class P3DAdapter implements IRotatable {
        public function P3DAdapter(p3d : SomePaperVisionObject) {
           _p3d  = p3d;
        }
    
        public function rotate(r :Number):void {
           p3d.rot = r;
        }
    }
    
    
    function someClientCode():void {
        var adapter : IRotatable = new P3DAdapter(p3d)
        new SomeLibraryClass().rotate(adapter, val));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing an open source wrapper for a COM object. I have
For an open source project I have I am writing an abstraction layer on
I am writing an open-source library to extract image metadata and store as XMP
I found this open-source library that I want to use in my Java application.
I am tasked with writing an authentication component for an open source JAVA app.
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
Is there any free open source library (in C/C++) for sockets that is widely
I need to invoke tesseract OCR (its an open source library in C++ that
I'm writing a piece of open-source client software that can connect to web services
I'm writing a Linux kernel module that needs to open and read files. What's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.