Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di felpone
    Registrato dal
    Jun 2010
    Messaggi
    182

    Dubbio programmazione ad oggetti

    Salve, il mio dubbio è sulla creazione di classi e uso di metodi indipendentemente dal linguaggio di programmazione (nel mio caso sto usando javascript).

    codice:
    //////////////////////////////////////////
    // VERTICES
    //////////////////////////////////////////
    
    
    function Vertice(x, y, z) {
       this.x = x;
       this.y = y;
       this.z = z;
    }
    
    
    Vertice.prototype.show = function () {
        return this.x + ":" + this.y + ":" + this.z;
    
    
       
    }
    
    
    //////////////////////////////////////////
    // GEOMETRY
    //////////////////////////////////////////
    
    
    function Geometry() {
        this.vertice = [];                   
    
    
    }
    
    
    Geometry.prototype.push = function(v) {
        this.vertice.push(v);
        
    
    
    }
    
    
    Geometry.prototype.show = function() {
        for(var i = 0; i < this.getVerticeCount(); i++){
             this.vertice[i].show();// undefined!
        }
        
        
    
    
    }
    
    
    Geometry.prototype.getVerticeCount = function() {
       return this.vertice.length;
    }
    
    
    
    
    /////TEST/////
    
    
    function test() {
    
    
       
       v  = new Vertice(2,4,6);
       console.log(v.show());
       g  = new Geometry();
       g.push(v);
       console.log(g .show()); //undefined
       
    
    
    }
    E' giusto il modo in cui ho creato le due classi? Oppure c'è troppa dipendenza tra la classe geometry e vertice perchè all'interno di geometry c'è il campo di tipo vertice?

  2. #2
    In che senso "c'è troppa dipendenza"? Le classi le fai ben per poterle usare/comporre, se non le usi non servono a niente.
    Amaro C++, il gusto pieno dell'undefined behavior.

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.