Function and Form

05 Dec 2017

Function and form. The form of an object must fit its’ function. When comparing a sports car to a semitruck, we notice that they are built very differently from each other. On one hand, the sports car is flat sleek with nice curves. On the other hand, the semitruck is built almost like a brick. It is both solidly built and rectangular prism in shape. For most people, when they look at these two vehicles, they do not think much about why they have very different forms. They just take for granted that the sports car, being built for speed is very aerodynamic. The sleek lines are meant to cut through the wind and the low profile is to keep the center of balance low to the ground when speeding along. When looking at the semi-truck, we instead see that it was built to be able to haul material. To this end, the semi-truck has a huge engine that is geared towards power and its trailer is box like to maximize the amount of items that can be packed into it. I have found the same to be true of the way people program. When programming, we often do not overtly think about the style in which we program, and when looking at two different programs, most people do not ask why do they look so different. Instead, most programmers make assumptions that the code is styled is formed according to the function that it is designed for.

Depending on the purpose of the program, the code is tailored to that task. If the code is being used as a base model for the creation of future developmental designs, we can use a Prototype Design Pattern. In this design pattern, the “Factory”, will determine which prototype instance to use as the base and each product is able to create new clones of itself. Through the use of this design pattern, the underlying logic can hidden from the user and thus allowing for the building of new instances from existing instances.

One of the Design Patterns that I personally have enjoyed using and believe to be most useful is called Model-View-Controller Design Pattern. In this particular patter, there is a model is the object that contains the data, a view which is used by the client to visualize the data that is contained within the object, and a controller that is used to manipulate the data within the object. In this Design Patter, it keeps the view and model separate. This pattern is often used when teaching new students in ICS to learn to program. For example, you may have a student.java class that stores the values of the data about students, a studentview.java class that allows you to view the items within the student object as defined within the student.java class. This studentview.java class would therefore include a print function. Lastly, we would have a StudentController.java class that would contain the functions that would allow us to manipulate the various values stored within the data structure. For example, you might have a setName(), setGPA, changeGPA, and other such function that would store, change, or delete a piece of data found within the model.

Just as in car design, we fist need to determine the purpose of our code and who are audience for our code is being designed for. Knowing the answers to those questions and also know the various design models, we can choose a starting point to our design that will allow us to use the best practices for each individual situation. This will then give us the greatest functionality and most efficient solutions to solving each programming problem.