GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 01:19:26 JST Paul Cantrell Paul Cantrell

    I am looking for a nice reading for students about using delegates instead of inheritance.

    By “delegates,” I mean instead of having an abstract class where subclasses fill in the blanks to customize a process, instead the superclass accepts an interface/protocol that a delegate object implements (à la UIKit).

    Just the basics. Simple is good.

    Anyone know of, say, a blog post or chapter from a book that covers this nicely?

    In conversation about 8 months ago from hachyderm.io permalink

    Attachments


    • Embed this notice
      Jenniferplusplus (jenniferplusplus@hachyderm.io)'s status on Wednesday, 02-Oct-2024 01:35:06 JST Jenniferplusplus Jenniferplusplus
      in reply to

      @inthehands This sounds like dependency injection? Is that what you're looking for?

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 03:47:20 JST Paul Cantrell Paul Cantrell
      in reply to
      • Jenniferplusplus

      @jenniferplusplus
      Not exactly, but related. Underlying mechanism is the same: depend on interface, someone else provides impl.

      DI is closely associated with testability, and is often used to replace an A→B dependency that could have been an explicit constructor call from A but instead you hide the impl of B (thus the “injection,” libs to allow swapping impls via configuration, etc).

      1/2

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 03:48:33 JST Paul Cantrell Paul Cantrell
      in reply to
      • Jenniferplusplus

      @jenniferplusplus
      The delegate pattern is for A→B patterns where B is tightly coupled to the •client• of A, e.g. A is a table view UI element and B provides the data to show in the table. Think callbacks, but expanded to have multiple entry points and possibly be stateful.

      2/2

      In conversation about 8 months ago permalink
    • Embed this notice
      Jenniferplusplus (jenniferplusplus@hachyderm.io)'s status on Wednesday, 02-Oct-2024 03:55:23 JST Jenniferplusplus Jenniferplusplus
      in reply to

      @inthehands I guess I still don't see what the difference is. If you have some class, like:

      class TableView : UIElement
      {
      new (ITableDataDelegate td)
      public void RenderElement()
      }

      Does that provide the behavior you're looking for?

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 04:02:27 JST Paul Cantrell Paul Cantrell
      in reply to
      • Jenniferplusplus

      @jenniferplusplus
      For sure! The difference is just intent / vibes. With DI, there’s a whole thing of having some kind of framework that lets you dynamically resolve the implementing class, maybe based on config or whether you’re in test mode or whatever. That whole role of the “injector” does not exist (and doesn’t make sense) for the delegate pattern.

      (Problem here may be that DI is an idea that’s drifted a lot, and means many things to many people.)

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 04:04:47 JST Paul Cantrell Paul Cantrell
      in reply to
      • Jenniferplusplus

      @jenniferplusplus
      Another way to highlight the diff: the alternative to DI is usually an explicit constructor call; the alternative to a delegate is usually an abstract class with a subclass.

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 04:08:34 JST Paul Cantrell Paul Cantrell
      in reply to
      • Steve Loranz

      @steveloranz
      It’s definitely under consideration! Just getting the lay of the land, looking for favorites I might have missed.

      In conversation about 8 months ago permalink
    • Embed this notice
      Steve Loranz (steveloranz@mastodon.social)'s status on Wednesday, 02-Oct-2024 04:08:35 JST Steve Loranz Steve Loranz
      in reply to

      @inthehands are you specifically staying away from the gang of four Design Patterns book?

      In conversation about 8 months ago permalink
    • Embed this notice
      Steve Loranz (steveloranz@mastodon.social)'s status on Wednesday, 02-Oct-2024 04:46:30 JST Steve Loranz Steve Loranz
      in reply to

      @inthehands yeah, I think in terms of generic description of the pattern, they do the best job with NeXT/Apple providing arguably the best examples of implementation, even if you just look at how their apis are organized. I'm a big fan of the ‘somethingIsAboutToHappen' and ‘somethingJustHappened' way they use delegation. I tried to recreate this as best I could in Python 2 years ago in a project called ImageFactory.

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 04:46:30 JST Paul Cantrell Paul Cantrell
      in reply to
      • Steve Loranz

      @steveloranz
      Yeah, that aspect of NeXTStep’s legacy is a really solid one, too oft overlooked.

      In conversation about 8 months ago permalink
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Wednesday, 02-Oct-2024 22:14:33 JST Paul Cantrell Paul Cantrell
      in reply to
      • Aidan Harding

      @aidanharding
      Oh, that sounds like exactly what I’m after and I don’t know the book! Will investigate.

      In conversation about 8 months ago permalink
    • Embed this notice
      Aidan Harding (aidanharding@fosstodon.org)'s status on Wednesday, 02-Oct-2024 22:14:34 JST Aidan Harding Aidan Harding
      in reply to

      @inthehands chapter one of Head First Design Patterns is about this. They build out an example using inheritance to share behaviour, then go to using composition instead, arguing why composition is usually better

      IMO, it's the most approachable and best programming design book out there

      In conversation about 8 months ago permalink

      Attachments


      1. https://cdn.fosstodon.org/media_attachments/files/113/236/889/288/315/363/original/f31f7bfab6c5f115.jpg
    • Embed this notice
      Aidan Harding (aidanharding@fosstodon.org)'s status on Tuesday, 08-Oct-2024 01:58:11 JST Aidan Harding Aidan Harding
      in reply to

      @inthehands you're in for a treat... such a great book!

      It achieves the feat of leading the reader into concepts so gently that they seem obvious by the time you get there.

      Which stands in stark contrast to the more typical approach of https://infosec.exchange/@lcamtuf/113071736083400018

      In conversation about 8 months ago permalink

      Attachments

      1. Domain not in remote thumbnail source whitelist: media.infosec.exchange
        lcamtuf :verified: :verified: :verified: (@lcamtuf@infosec.exchange)
        from lcamtuf :verified: :verified: :verified:
        Attached: 1 image Ah yes, I remember buying that textbook
    • Embed this notice
      Paul Cantrell (inthehands@hachyderm.io)'s status on Tuesday, 08-Oct-2024 01:58:11 JST Paul Cantrell Paul Cantrell
      in reply to
      • Aidan Harding

      @aidanharding
      We did end up assigning a large excerpt of chapter 1 of the book, and I’d say response to it from the students has been really positive. It really seemed to click for them, and it’s a nice stepping stone to Wednesday’s reading from Effective Java. Thanks so much for the good recommendation!

      In conversation about 8 months ago permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.