Friday, July 25, 2008

Silver Eagle Dixie Chopper

OPENGL and GLUT for Mac OS X

Le opengl sono già installate e si possono reperire al seguente path :
Macintosh HD / Sistema / Libreria / Frameworks / OpenGL.framework
Inoltre bisogna installare il framework GLUT che per il mac è reperibile al seguente indirizzo : http://developer.apple.com/samplecode/glut/index.html, scaricare il file zip e decomprimerlo. Aprire un terminale e spostarsi dentro la cartella appena decompressa e digitare :

xcodebuild install

sudo ditto /tmp/GLUT_External.dst/System/Library/Frameworks/GLUT.framework/System/Library/Frameworks/GLUT.framework

Ora la libreria GLUT è installata per fare una verifica portarsi nella cartella frameworks, dove precedentemente abbiamo controllato se erano presenti le opengl e controllare che ci sia la cartellla : GLUT.framework.

Se ne file sorgente is GL / glut.h must change with GLUT / glut.h.

Open Xcode, create a new C + + Tool, enter the name you want, press the button, right mouse over the name of the newly created project with the icon of Xcode and choose add and sub menu, choose External Framework and select the folder OpenGL.framework and GLUT.framework, delete the file main.cpp and enter your source files. Now press the Build-and-go and the program should start.

Tuesday, July 22, 2008

Washing Hair After Thermal

Principles of Object Programming - Part 3

Prefer composition to inheritance

Skep, after completing the design of its soldiers, who now can conquer the world, you realize one important thing: choosing a has-a relationship rather than inheritance gave more flexibility his plan. Not only has the choice of a family of algorithms easily, but also gave him the opportunity to change at runtime the algorithm to use .

If, as it should be the aim of a design object is the easy reuse and maintainability of the code, the composition definitely wins in the efficiency with respect to inheritance. This concept, or maintainability, it is important also for the fact that during the course of vito software, the stage longer and perhaps harder is definitely the maintenance, which often also involves deep changes to the software created. Giving the ability to dynamically change the software can make maintenance much faster: even the implementation of the methods can remain the same and can only change their call dynamic. Sometimes the

choice between inheritance and composition can be very complicated : In some occasions the two principles may seem absolutely equivalent until we reach a point (applying Murphy usually towards the end of the design of a component) in which one of two behaviors becomes obviously better to use.

In general, during the design, it is good to keep in mind this rule:

Using inheritance as a objects behave like any other, rather than when it seems a subtype .

A case of this example is: Suppose two classes, Rectangle and Square. Obviously, an initial analysis would say that the proper relationship between the two is an is-a relationship in the sense that Square is-a Rectangle, quantp in the square is a special case of the rectangle with the sides all having the same size. But suppose that the class Rectangle abbia ragionevolmente due metodi, setHeight() e setWidth() che ne modificano altezza e larghezza. Square eredita i due metodi ma una volta che vado a chiamarne uno di essi su square evidentemente non succede ciò che volgiamo, rompendo il principio che Square dovrebbe essere un diretto sostituro per Rectangle. Quindi in questo caso l'idea is-a si applica logicamente ma i due oggetti non si comportano allo stesso modo, finendo per dare risultati inattesi.

Comunque sia Skep si ricorda di aver già visto uno schema delle classi come il precedente. Quello finora descritto infatti è il design pattern Strategy , che formalmente può essere descritto così:

Strategy ha lo scopo di definire a family of algorithms, encapsulate it and make them interchangeable. Strategy lets algorithms vary independently from clients and use them.
(Design Patterns, Gamma, Helm, Johnson, Vlissides)