Skip to main content
Engineering LibreTexts

3.7: Organizing Methods into Protocols

  • Page ID
    40053
    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Before we define any more methods, let’s take a quick look at the third pane at the top of the browser. In the same way that the first pane of the browser lets us categorize classes into packages, the protocol pane lets us categorize methods so that we are not overwhelmed by a very long list of method names in the method pane. These groups of methods are called ”protocols”.

    The browser also offers us the --all-- virtual protocol, which, you will not be surprised to learn, contains all of the methods in the class.

    If you have followed along with this example, the protocol pane may well contain the protocol as yet unclassified. Right-click in the protocol pane and select categorize all uncategorized to fix this, and move the initialize method to a new protocol called initialization.

    How does the System Browser know that this is the right protocol? Well, in general Pharo can’t know exactly, but in this case there is also an initialize method in the superclass, and it assumes that our initialize method should go in the same protocol as the one that it overrides.

    A typographic convention. Pharoers frequently use the notation Class >> method to identify the class to which a method belongs. For example, the cellsPerSide method in class LOGame would be referred to as LOGame >> cellsPerSide. Just keep in mind that this is not Pharo syntax exactly, but merely a convenient notation to indicate ”the instance method cellsPerSide which belongs to the class LOGame”. (Incidentally, the corresponding notation for a class-side method would be LOGame class >> someClassSideMethod.)

    From now on, when we show a method in this book, we will write the name of the method in this form. Of course, when you actually type the code into the browser, you don’t have to type the class name or the >>; instead, you just make sure that the appropriate class is selected in the class pane.


    This page titled 3.7: Organizing Methods into Protocols is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.