59

There are beautiful answers to this question already here, and I will not try to reiterate any of the ground that has already been covered. However, something important that I have not seen here so far is that comparing OOP to FP is not actually terribly meaningful. It's a bit like comparing glass (the material) to tables (the furniture). They each have ...


44

Learning about references is important, but I don't feel that learning about pointers is that important for beginning Java students. Certainly intermediate students will need to understand them. When I started learning about pointers, I had a hard time grasping them at all until I learned assembly language. Once I learned assembly (for any processor), ...


44

I'm not as familiar with Python as I am with other languages, but I'm sure your students have played Minecraft. If you haven't, I suggest taking a few minutes to find some introductory "Lets Play" videos on YouTube first. Let's talk Blocks. Minecraft has dozens of blocks. Dirt, some, water, colored wool... All blocks can be broken, picked up, placed, ...


31

Here's an analogy that I've used for several years, and that students seem to understand. It doesn't focus on the rules, but why we have public and private and protected. "Most of you know that I live down at the beach. If you find yourself riding past my house, and it's hot outside, you might come to my front door, knock and ask if you could have a soda. I ...


31

For a beginning course: no. I have helped clarify behavior for fellow students who got lost by an instructor who explained things in terms of pointers. I have programmed in C, and most of my current programming is done in Rust; I understand pointers and what problems they are best suited to solve. But in Java, you don't have any access to pointers, so ...


16

No Because of the way that you learn, you think of them as fundamental, to the way references work. They are not. References do not have to work this way. [I would still agree that pointers are fundamental to understanding memory in Von Neumann / Harvard architecture.] Java uses references. You can think of these as being pointers, that must point to a ...


16

Here I will discuss Functional Programming (FP) and Object Oriented Programming (OOP) in a fairly pure form. Actual languages, however often make compromises to allow older forms as well as multi-paradigm programming. Both FP and OOP rely in the notion of program "State" but do so in different ways. In fact there are really two different things that go by ...


16

Too many examples that you find are (IMO) fatally flawed. The Animal->Dog is especially flawed, though widely used. The problem is that these sorts of examples almost require that the superclass has a certain set of public methods that isn't the same as that of the subclass, requiring you to add additional public methods to the subclass. This is because an ...


13

What my teachers used was the following example, which is pretty simple and most people understood. Your father orders a pizza. The delivery guy arrives and expects payment. The wallet containing the money belongs to the object father If the wallet is private, then you have to get your father to open it and pay. If the wallet is protected, you can go and ...


13

What is important is to teach students the difference between Java objects, and Java variables. There are thousands of questions on Stack Overflow asked by students and by junior developers who do not understand the difference. When we write Foobar f = new Foobar(...), it's much easier to say that f is a Foobar than it is to say that f holds a reference to ...


13

There are a number of different ideas that are all called OO. I'm going to focus on the Simula-style OO. Here's my fiction which I think isn't too far off from reality: As computers became more powerful, the amount of entities in an model started to grow. In addition, the different types of entities in these models was also increasing. These models had ...


12

I've got to jump in here and talk about my experience having to help a former boss understand why the project he wanted to do wasn't possible in the time available. It came down to incompatible data types and he just couldn't see why I couldn't convert from one to the other (he wanted to do real-time motion capture using an XBox Kinect to animate a 3D mesh ...


11

Ooh, this is one of my favorite lessons! I don't introduce package private and protected in the same lesson as private and public, because there are 3 principles that I want them to absorb that ultimately motivate the entire system. My lesson introduces a few more ideas than just permissions (it's really how I get started with Ojects), but the key ideas of ...


11

A related (rhetorical) question: Should C students be taught the [machine language] idea of reusing a pointer as a CPU instruction if the value happens to line up? The speaker in a Functional Programming talk I recently saw discussed part of the history of programming languages, and the opinion seriously held by some at one time that assembly language was ...


11

Even though you mention fearing the complexity of looking at wrong turns in its development, I think it is still instructive to change the question from "What would lead to the invention of object-oriented programming?" to "What did lead to the invention of object-oriented programming?" You don't have to give the complete history to pull out the main ...


10

I've got one that might help, modified/simplified from an actual problem I had to solve at my current job. Imagine you're writing a Content Management system - this system will store four types of documents (and the Meta/Index information for them) PDFs (who created, description, file size) Word documents (who created, description, file size) Pictures (who ...


10

As a professional software developer, I would recommend minimizing the time spent teaching UML. Teach the patterns. If they learn some UML along the way, so much the better. But don't burden them. In my experience, I've found value in using UML for somewhere around 3-5% of my work. It usually provides its value after the fact, once I've already ...


10

You are teaching a course on design patterns, not on UML. You just happen to be using UML for the graphical notations. As UML is not the subject, don't spend too much time on it. Spend just enough time so that your students understand what you mean with each symbol that gets used in class as if it were a notation you invented, but also tell them it is ...


9

As someone who learned to program with ruby, I think that the concept of how a reference to an object works under the hood is vital. Having the knowledge that "under the hood" my variables may be represented as pointers to values makes certain things much easier to understand. For example, in ruby: a = Object.new b = a.clone c = a c == b #=> false c == a ...


9

FP and OOP are both tools in the box, none of them is better or worse. The same way you would not ask whether to use a hammer or a screwdriver to put in a nail, you should not ask whether to use FP or OOP. The question should be: what is the best way to solve your problem at hand? OOP excels when you need to describe abstract objects with code (hence the ...


9

I wouldn’t expect to find a comparison table because OOP and FP are not mutually exclusive concepts. OOP is about encapsulating data in objects behind interfaces and using inheritance to build objects in re-usable pieces. FP, however, is about not changing states or having side-effects. You can have an OOP program with immutable objects. (You can clone an ...


9

There are already several good answers, but I'd like to add the following. Functional code is (at least in theory) more easily parallellized. This is important because we've about hit the limit of how fast we can run integrated circuits. (I know that's an oversimplification; I'm trying to keep it simple for the OP's audience's sake.) So, while you can't ...


8

tl;dr: When you teach with the OO paradigm, you get to control the flow of ideas and the level of complexity at any moment. Here we examine the first course in computing, no matter the educational level. Presumably this is for a formal course, though it can be adapted to self-study. Presumably the students have mixed ability and backgrounds, neither all ...


8

From my software engineering experience. Some of it is useful some is not. It was put together by a committee of organisations that had a product to sell. (state machines got in there because a committee member had a state-machine editor.) A lot of other useful stuff was missed out. Take what is useful, leave the rest, and use stuff from elsewhere. ...


8

No, you don't need to talk about pointers in an introductory Java class. You should talk about references, but even then you should keep it at a very high level. The best tutorial on references I've seen is Cup Size -- a story about variables and its follow up Pass-by-Value Please. These talk about variables as cups that can hold different items, and ...


8

Ideally, interfaces come first. Before Classes. Interfaces define concepts. Classes implement those concepts. Don't think of them as an add-on to OO programming. Think of them as the essence. In fact, if you present a pre built class to students, my guess is that you already, probably informally, give the interface first. Here is a class with public ...


8

My coding school gave one particular (weeks-long) project that I felt nailed the concept of inheritance, and why it could be useful: Simulating a circuit board with logic gates. The framework of the exercise can be adjusted, but here's a short example: A circuit board is composed of circuit inputs, logic gates and circuit outputs; each of these ...


7

A good analogy might use animals and their classification. Class: think felines. A feline will purr, go out only at night, eat meat, etc. One could think of the methods purr, goOut:time, eat:food, where a valid feline will only accept a night time and food that is meat. Inheritance: meanwhile, felines are very different from each other, despite sharing ...


Only top voted, non community-wiki answers of a minimum length are eligible