Hardware Reference
In-Depth Information
door if you have an error in your program that means it fails to unlock the door! If your
Raspberry Pi is on the inside of your door, it can be useful to have remote access to it so that
you can stop or edit your program. Look up how to SSH into your Raspberry Pi online for
more information.
Object-Orientated Programming
You have seen how easy it is to swap blocks out with OOP. OOP allows programmers to
structure their code by creating and using objects as they may do with real-world objects.
Think of a real-world object - it has a set of properties (characteristics, such as its colour)
and a set of things that you can ask it to do. As an example, think of a balloon - there is data
about the balloon, properties that it has - for example, it may have the colour red and be
inlated. There are actions you can cause the balloon to do, such as inlate or pop. These
actions may affect the balloon's properties; causing a balloon to pop will cause its is
Inflated property to change from true to false.
The key thing to notice about OOP is that it organises functions and variables together. In
the door lock example the variable tags is only useful to the RFID authentication part of the
program, so it is part of the RfidFileAuthenticator class. The alternative would be to
have all the variables together, which would be more confusing as you would not know
which part of the program needed them. If you were working as a part of a team on a pro-
gram, OOP would provide a way to split the code into fairly independent parts that can be
worked on separately and eventually assembled.
OOP is there to help you write programs by providing a framework for structure. Objects
can be swapped out as you have seen. You can also build more complex objects from com-
ponent objects, just as you can in the real world. As you become more advanced, you can
learn about another feature of OOP, inheritance, which enables you to create child objects
that inherit the behaviour and variables of their parents, but with additions.
You don't have to write in an OOP style, but using it can be a great help. In the code lock
example it allows you to change behaviour by swapping an object in one line. This is only easy
because the OOP helps manage abstraction, breaking a problem into manageable parts.
Networking Multiple Doors
Now that you have one door lock working it's time to think about expansion. Imagine in the
future that you have lots of door locks, and want to allow access to some of the doors to
other users. With the current system you would have to visit each door controller and set the
same password. It might also be hard to keep track of who has access to each door.
 
Search WWH ::




Custom Search