Results 1 to 6 of 6

Thread: classes vs access

  1. #1

    classes vs access

    Delphi/FreePascal
    Object Oriented Programming

    I have 2 classes. Class 2 is passed to Class 1 as on object. Class 1 then uses procedures in the object (Class 2). Now you can also use Class 2 directly. E.g. create it before passing it on as an object to the Class 1 object. Now i want to hide some procedures when Class 2 is used directly as some procedures only make sense when called from Class 1.
    Both are in the same source file. What options do i have to hide some procedures from Class 2 when used directly but be available when called from class 1.

    Thanks for your answers in advance.
    http://3das.noeska.com - create adventure games without programming

  2. #2

    classes vs access

    You can make all procedures in class2 that should be available only to class1 private. Private methods and fields can be accessed by any other class in the same unit file.

  3. #3

    classes vs access

    I can do that but somehow it does not feel right. But i go use that for now. Thanks.
    http://3das.noeska.com - create adventure games without programming

  4. #4

    classes vs access

    If I understood it correctly, it seems like a perfect usage of the "strict private" declaration range.

  5. #5

    classes vs access

    I always assumed that private was to be used in the class where it is declared. And not from the outside not even from the same unit.
    http://3das.noeska.com - create adventure games without programming

  6. #6

    classes vs access

    Private is used to hide methods, properties, and fields from others classes. But there's some kind of "friendship" within a unit, so other classes in the same unit can everything you declared as private. Strict private can make your declarations visible only within the class, ignoring the "friendship" in the unit.

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
  •