Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: [opinion][Research] API design

  1. #11
    There are a lot of nice advices here. Thanks to all.

    Quote Originally Posted by SilverWarior View Post
    One piece of advice. If you are extending some class with new functionality it is recommended to change the name of the extended class in order to avoid confusing it with the original class that it was extended from.
    Yes, I've learned that the hard way.

    The injection thing is interesting but I think I'll not do that way.

    Quote Originally Posted by drezgames View Post
    Maybe this:
    <Action><Object><Attribute/State>();// Do an Action over some Object Attribute/State
    This is how I tend to make my APIs, more info about this here:
    raylib syntax analysis · raysan5/raylib Wiki (github.com)
    That's a nice way. Maybe I should review my API now I'm (re)starting it.

    Quote Originally Posted by Chebmaster View Post
    The second one BUT use classes with class (static) methods instead of unit names.
    This way you *cannot* call method without specifying which.
    And can pack several ones in the same unit
    And move them between units if you need to change architecture -- without touching the calling code
    I didn't realize I can do that. I did in some PHP projects but forgot completely there are also static class methods and properties in Pascal. Since I'll revisit my API I'll see how this may fit with the old-school I want to archieve.
    No signature provided yet.

  2. #12
    Well, I was working in this new API Chebmaster suggested and I must say I like it. It isn't as classic as I initially intended (pure Pascal, nothing classy) but it looks nice and is easy to read and maintain.

    There are some quirks. For example, IMO this looks a bit odd:
    Code:
    var
      AnimationInfo: TmngAnimationInfo; { A record. }
      Animation: TmngAnimation; { Another record. }
    begin
      ...
    { Gets animation information. }
      mngAnimation.Assign (Animation, AnimationInfo)
      ...
    end;
    So it forces me to add methods to the records:

    Code:
    var
      AnimationInfo: TmngAnimationInfo; { A record. }
      Animation: TmngAnimation; { Another record. }
    begin
      ...
    { Gets animation information. }
      Animation.Assign (AnimationInfo)
      ...
    end;
    I think I can live with it, specially because the disk access (including an IFF implementation) is done by thread classes.

    I'm also wondering if type declarations should be inside the static classes like:

    Code:
    var
      AnimationInfo: mngAnimation.TAnimationInfo; { A record. }
      Animation: mngAnimation.TAnimation; { Another record. }
    begin
      ...
    { Gets animation information. }
      Animation.Assign (AnimationInfo)
      ...
    end;
    Anyway there are a few functions and procedures I'll keep outside the static classes (for example, the mngInitialize function that initializes the engine).
    No signature provided yet.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •