# Introducing Another Object Orientation System

This is the first of a series of posts related to object oriented programming in R and the package aoos. The second introduces version 0.2.0.

R has more than enough systems for object orientation and here is yet another one. S3 and S4 are the built in systems. R.oo has been developed since 2001; proto since 2005; and R6 is the newest and published to CRAN in 2014.

What I wanted to have is a system where method definitions are part of the class definition. Something which forces me to define functions belonging to one concept in one place, however, I don’t feel comfortable to define them inside lists. Furthermore I wanted to have auto-complete in R. So here I present my solution for your consideration. See also the vignette for the package if you should be interested in some more details.

As an example for this post consider the class Directory. defineClass is used to define a new class. The second argument is a R-expression. Every assignment in that expression will define a field or method. By default everything is private, if you want something to be public you have to use the function public.

The class Directory is basically a S4 class and inherits from environment. You can only access public member; and the return value of defineClass is the constructor function, so you can use Directory() to create an instance of Directory. Arguments to the constructor are passed on to the init method if you have defined one.

On initialization a directory is created if it doesn’t exist. We start with a directory named ‘foo’. I also defined some S4-methods, show to print some file infos to the console and two binary operators. / will be like a ‘slash’ and - will delete files from the directory.

If you are still interested, you can install the package from Github or CRAN.