How much Abstraction is good abstraction?

Abstraction, is a word that in simple terms means ‘to remove from’ or ‘draw away’ and in terms of software development that is like a function say floodFill(xPos, yPos) so all you need to do is call the function, you do not know how this is implemented as you have no access to the underlining code. When you use languages like C or C++, you have to write all of the code yourself, where as many high level languages offer you abstracted objects that do a lot more for you, so literally you can write code like this below to make a 2D Board Game

this would present you with a board that is 10×10 using the textures from an image file called board.png, the player image or images are found in the image player.png and the enemies are from the images called alien1, alien2, alien3, alien4 and boss.

How much abstraction?

You have heard of Pixel editors, I had created a bitmap editor for iOS which would allow the user to tap on screen and toggle the pixels on or off and at the end it you could save that as an image. You could create this in just one line such as

This could then create the pixel editor including the menus and options to save the file, etc.

So the question is how much abstraction should you have?

Advantages of Abstraction

There are a lot of frameworks that provide abstraction to make games. Taking a sample from Lua powered CoronaSDK, you can animate an object by simply using a transition.to or a transition.from block. This in contrast to using Swift is literally a line of code vs creating an animation, setting the parameters for the same.

in swift you could use something like

in contrast to using

While this is a simpler example, this is more useful with complex objects like accelerometer and GPS, where you can access these with a couple of lines.

If you think that this is something new, well not exactly, it is something that has been in use by iOS developers for a long time, examples are alertBoxes , MFMessageComposerViewController or MFMailComposerViewController . While these are self contained viewControllers, which is another way to add abstraction.

Swift context

In the context of swift, you can also create static functions in an structure or a class. You can use cocoapods like AlmoFire for networking which provides a much better interface than creating a NSURLSessionTask then setting the delegates to handle it and finally calling resume to start the data task. Alternatively you can simply use almofire in literally one line of code, or write your own abstraction like

What do you think about abstraction and do you use that in your applications or do you write the same code over and over again?

Views All Time
Views All Time
240
Views Today
Views Today
1
Posted in Uncategorized.