Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Fondamenti di architettura e programmazione > [HELP] clone()
Pages (2): « 1 [2]   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
sbrandu
.consigliere.

User info:
Registered: May 2004
Posts: 148 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 21:31:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

A me compila ed esegue senza errori la classe Programma.java (quella per il testing).. ora non so se fa tutto quello che è richiesto nel modo giusto, ma me lo fa credere il fatto che funzioni tutto

01-02-2006 17:12
Click Here to See the Profile for sbrandu Click here to Send sbrandu a Private Message Find more posts by sbrandu Add sbrandu to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
unid
.consigliere.

User info:
Registered: Nov 2005
Posts: 123 (0.02 al dì)
Location:
Corso: Laureato
Anno: Laureato
Time Online: 22:18:48 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Secondo me il metodo clone deve essere implementato in ogni classe... ma SOPRATTUTTO deve essere statico in modo che ad esempio da Sequenza si possa accedere al metodo clone di Dichiara o Assegna o tutti gli altri.... Dato che a priori io non so che istruzione contiene Sequenza... posso fare un test ad esempio così:

public static Object clone(){
Object o = new Object();
if(this instanceof Dichiara){
.....
}
.....
}

e in Dichiara il clone è semplicemente così:

public static Object clone(){
Object o;
...

Intervento del moderatore:
Codice Limato


voi che ne dite?

Last edited by ciops on 02-02-2006 at 10:11

01-02-2006 18:17
Click Here to See the Profile for unid Click here to Send unid a Private Message Visit unid's homepage! Find more posts by unid Add unid to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ARIEL
.grande:maestro.

User info:
Registered: Jul 2005
Posts: 636 (0.08 al dì)
Location: milano
Corso: Comunicazione digitale
Anno: Dottoressa!!!
Time Online: 12 Days, 7:36:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Scusate ma se il metodo clone() è astratto in Istruzione non può essere richiamato in quanto non ha un corpo e andrebbe perciò implementato in ogni classe....ma come cosa mi pare abbastanza dispendiosa soltanto che il testo non chiarisce bene come gestire il metodo clone().....qualcuna sa di preciso come va fatto?
Grazie

01-02-2006 20:42
Click Here to See the Profile for ARIEL Click here to Send ARIEL a Private Message Find more posts by ARIEL Add ARIEL to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Vikyg13
.arcimaestro.

User info:
Registered: Feb 2006
Posts: 290 (0.04 al dì)
Location:
Corso: Comunicazione Digitale
Anno: Primo
Time Online: 3 Days, 1:12:06: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Premetto che io nn ho definito clone() come astratto in Istruzione, in modo da ridefinirlo solo nelle classi che rappresentano realmente delle istruzioni (nn so se sia giusto).
Seguendo quanto scritto nel link io ho messo nella classe Istruzione (public abstract class Istruzione implements Cloneable) :

public Object clone() {
try {
return super.clone();
}
catch (CloneNotSupportedException e) {
return null;
}
}

Per definire il metodo invece nelle singole Istruzioni ho messo ad es. in Dichiara:

public Object clone() {
....

Intervento del moderatore:
Codice Limato


In qsto caso però mi dà un errore nella riga in grassetto dicendo che clone è dichiarato protected nella classe Object. Qualcuno mi sa dire come mai e cosa dovrei fare??
Per il metodo clone() in Dichiara ho sempre fatto uso del link dove spiega come clonare un oggetto in maniera "approfondita".

Last edited by ciops on 02-02-2006 at 10:12

01-02-2006 23:37
Click Here to See the Profile for Vikyg13 Click here to Send Vikyg13 a Private Message Find more posts by Vikyg13 Add Vikyg13 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ARIEL
.grande:maestro.

User info:
Registered: Jul 2005
Posts: 636 (0.08 al dì)
Location: milano
Corso: Comunicazione digitale
Anno: Dottoressa!!!
Time Online: 12 Days, 7:36:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Il problema è che nel testo del progetto viene specificato che il metodo clone() in Istruzione deve essere astratto quindi penso che bisogna attenersi a quanto viene detto...

02-02-2006 09:02
Click Here to See the Profile for ARIEL Click here to Send ARIEL a Private Message Find more posts by ARIEL Add ARIEL to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
sandrino83
maschio latino

User info:
Registered: Oct 2004
Posts: 376 (0.05 al dì)
Location:
Corso: Com Dig
Anno: finito
Time Online: 8 Days, 7:53:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ariel ha ragione....è obbligatoriamente astratto.......qualcuno è riuscito a farlo funzicare????

__________________
we are just two lost souls swimming in a fish bowl year after year....running over the same old ground....what have we found.......

02-02-2006 10:04
Click Here to See the Profile for sandrino83 Click here to Send sandrino83 a Private Message Find more posts by sandrino83 Add sandrino83 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ARIEL
.grande:maestro.

User info:
Registered: Jul 2005
Posts: 636 (0.08 al dì)
Location: milano
Corso: Comunicazione digitale
Anno: Dottoressa!!!
Time Online: 12 Days, 7:36:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Penso che vada dichiarato astratto e implementato in ogni classe anche se a me sembrano tutti uguali alla fine! Cmq usando il clone di Clonable funziona ma penso sia errato!

02-02-2006 10:22
Click Here to See the Profile for ARIEL Click here to Send ARIEL a Private Message Find more posts by ARIEL Add ARIEL to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
sbrandu
.consigliere.

User info:
Registered: May 2004
Posts: 148 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 21:31:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Allora..
Io credo che il metodo clone sia obbligatoriamente da dichiarare astratto nella classe astratta Istruzione.
Io ho poi utilizzato il clone() di object nelle classi estese a Istruzione per copiare l'oggetto di classe.
Facendo così ogni volta che si richiama il metodo clone su una qualsiasi istanza della classe Istruzione verrà invocato il metodo clone() della corrispondente sottoclasse estesa.

public Object clone() {
Object obj = new Object();
...

Intervento del moderatore:
Codice Limato


Così tutto sembra funzionare.. ma sono sempre ben accette soluzioni alternative soprattutto se migliori della mia.

Last edited by ciops on 02-02-2006 at 13:14

02-02-2006 12:47
Click Here to See the Profile for sbrandu Click here to Send sbrandu a Private Message Find more posts by sbrandu Add sbrandu to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 16:58.    Post New Thread    Post A Reply
Pages (2): « 1 [2]   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.066 seconds (64.12% PHP - 35.88% MySQL) con 25 query.