From Struct to Class

After extracting Data Clumps to (C style) structs, we want to go further and make real classes.

Learning Goals

Session Outline

Connect - Web Hunt on Information Hiding

Web Hunt on the following question: What is Information Hiding? What is Encapsulation? Why do we want them?

The following things could come up:

Besides the connect part, this helps you to assess if participants know the theory.

Concept - Converting Struct to Class

Start with Lecture of two slides to summarise both concepts:

Information Hiding:

Encapsulation:

Demo

Do a 5 minute demo how to convert a struct to a class (recording or slides). Using an example of a student struct the following steps are necessary:

Concrete Practice - Hero Quest

The Hero Quest Refactoring Kata contains some pieces of code from a RPG dealing with players and items. Either continue after the previous learning hour or use the branch with_struct, where the structs have been created. People work in pairs and follow the steps to convert the existing structs to classes in a safe way. They also need to encapsulate their data.

Facilitation Hints

In half an hour people can do one iteration, i.e. convert one class and moving one or two methods into it.

Conclusions - Summarise Benefits

Ask the group to summarise the benefits of grouping data and methods together. Also ask for encapsulation.