Hey guys

Hey guys,

How do I create a "internal" class for an unit? For that other users are not able to use it, I wish the class was not nested in another one.

Is there something as .NET-like internal modifier for Delphi? :D

Thanks in advance :D

Comments

  1. Put it in the implementation section.

    ReplyDelete
  2. Why does it need to be internal? I ask because every time someone brings up such question it's mostly to restrict access to such class to anyone consuming the library. I agree that in .Net is makes the public interface cleaner because you only have access to non internal things it does not serve any purpose apart from that.

    Putting such a class into the implementation section in Delphi has to be considered because this cannot used anywhere outside of that unit (while in .Net you can access an internal class inside the entire assembly). That might lead to problems if another unit needs that class as well. And such class cannot be tested in any clean way (no, making special defines and stuff for testing only is not clean).

    ReplyDelete
  3. Stefan Glienke  it's enough to create a project which uses it in its own unit and you can test it.
    Thsi also tests how depending it is on other classes etc.

    No big deal imho.

    A

    ReplyDelete
  4. Andrea Raimondi Remember that I said you should consider putting units into the implementation part because that comes with a price - I did not say "never do that" as someone else would have.

    ReplyDelete
  5. The only real trouble would be regressions. I wonder whether there is any way to help with that... Who is the guy who does Delphi plug-ins? Anybody remembers his name?

    A

    ReplyDelete
  6. I prefer putting them in a separate unit. So if I have a "FoodOrders.pas", which might define a IFoodOrder interface, I'll put the implementation in the unit "FoodOrders.Detail.pas".

    This way the implementation details (hence the name) are clearly marked as such, yet available if one really needs it (which, along the road, one sometimes do).

    ReplyDelete
  7. Andrea Raimondi No clue who you are referring to, there are several people making Delphi plug-ins these days.

    ReplyDelete

Post a Comment