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 > esercizio UML
  Last Thread   Next Thread
Author
Thread    Post New Thread    Post A Reply
Paul442
.consigliere.

User info:
Registered: Nov 2006
Posts: 130 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:34:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
esercizio UML

Ciao, avrei bisogno di chiedere una cosa che non hoi capito:
negli esercizi UML degli esami nel caso non trovassi un metodo nella classe appena sopra, posso usare metodi anche della classe due posti in su?
faccio un esemio:
se la gerarchia è A <- B <- D se io sono in D posso usare metodi che si trovano anche nella classe A oltre che nella classe appena sopra (ovvero la B) ?

Grazie

15-12-2010 08:58
Click Here to See the Profile for Paul442 Click here to Send Paul442 a Private Message Find more posts by Paul442 Add Paul442 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
zack1988
.primate.

User info:
Registered: Oct 2007
Posts: 75 (0.01 al dì)
Location: Milano
Corso: Informatica
Anno: 1
Time Online: 2 Days, 2:43:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ciao,
A <- B <- C visto che B eredita i metodi di A anche C gli eredita, come test ho provato usando java:

PHP:

public class A {
    public void metodoA() {
        System.out.println("METEODO A");
    }
}

public class B extends A {
    public void metodoB() {
        System.out.println("METODO B");
    }
}

public class C extends B {
    public void metodoC() {
        System.out.println("METODO C");
    }
}

public class Test {
    public static void main(String [] args) {
        C istanzaC = new C();
        istanzaC.metodoA();
        istanzaC.metodoB();
        istanzaC.metodoC();
    }
}

Last edited by zack1988 on 15-12-2010 at 10:56

15-12-2010 09:23
Click Here to See the Profile for zack1988 Click here to Send zack1988 a Private Message Find more posts by zack1988 Add zack1988 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Paul442
.consigliere.

User info:
Registered: Nov 2006
Posts: 130 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:34:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Grazie mille della risposta quindi se per esempio in un esercizo dello scritto io ho
c.f( 3 + 3.0 ): ma ho +f(double x): int NON in C, e neanche in B ma si trova in A posso restituire come risultato f(double x) in A? è corretto?

15-12-2010 09:29
Click Here to See the Profile for Paul442 Click here to Send Paul442 a Private Message Find more posts by Paul442 Add Paul442 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
zack1988
.primate.

User info:
Registered: Oct 2007
Posts: 75 (0.01 al dì)
Location: Milano
Corso: Informatica
Anno: 1
Time Online: 2 Days, 2:43:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Da quello che ho capito tu hai un metodo in A che è f(double x) e vuoi che sia ereditato in C allora visto che A <- B <- C quindi puoi farlo:

Sempre usando java:

PHP:

public class A {
  public void f(double x) {
    System.out.println(x);
  }
}

public class B extends A {}

public class C extends B {}

public class Test {
  public static void main(String [] args) {
    C istanzaC = new C();
    istanzaC.f(10);
  }
}

15-12-2010 10:53
Click Here to See the Profile for zack1988 Click here to Send zack1988 a Private Message Find more posts by zack1988 Add zack1988 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Paul442
.consigliere.

User info:
Registered: Nov 2006
Posts: 130 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:34:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

nel compito del 21-01-2010 l'UML era cosi strutturato:
A
+f(long x): int

B
+f(int x): int
+f(double x): int

A a;
B b;
C c;
D d;

a = new B();
b = new B();
c = new D();
d = new D();

Non capisco perchè
• a.f( 3.0 ): ha come soluzione ERRORE! in teoria essendo che a = new B(); non dovrebbe prendere F(double x) in B?

15-12-2010 15:13
Click Here to See the Profile for Paul442 Click here to Send Paul442 a Private Message Find more posts by Paul442 Add Paul442 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
zack1988
.primate.

User info:
Registered: Oct 2007
Posts: 75 (0.01 al dì)
Location: Milano
Corso: Informatica
Anno: 1
Time Online: 2 Days, 2:43:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

potresti passarmi il testo del compito.

CASO 1:
A <- B (B estende A)
L'eredita è a senso "unico" il figlio prende le propietà dal padre e non il contrario.

Quindi in questo caso quando hai istanziato a : A a = new B();
facendo a.f(double) va in errore perchè la classe A non ha visibilità dei metodi e delle propietà di B, quindi non trovando il metodo f con parametro double.

Per poter accedere al metodo devi eseguire il casting:
B b = (B) a;

CASO 2:
B <- A (A estende B)
allora andava in errore quando tentavi di inizializzare
a = new B();

15-12-2010 17:09
Click Here to See the Profile for zack1988 Click here to Send zack1988 a Private Message Find more posts by zack1988 Add zack1988 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Paul442
.consigliere.

User info:
Registered: Nov 2006
Posts: 130 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:34:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Grazie mille!

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

User info:
Registered: Nov 2006
Posts: 130 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:34:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

scusa ma rileggendo tutto l'esercizio (che ora ti allego qua in pdf) forse nn mi è ancora del tutto chiaro...non dovrebbe essere la stessa cosa anche per
• c.f( 3 + "ciao".length() ): ?
xke qua invece va bene?
Grazie

Attachment: scr21-1-10.pdf
This has been downloaded 7 time(s).

15-12-2010 18:04
Click Here to See the Profile for Paul442 Click here to Send Paul442 a Private Message Find more posts by Paul442 Add Paul442 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
zack1988
.primate.

User info:
Registered: Oct 2007
Posts: 75 (0.01 al dì)
Location: Milano
Corso: Informatica
Anno: 1
Time Online: 2 Days, 2:43:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

3.0 è un double invece 3 + 4 (lunghezza di "ciao") è intero.
in A hai il metodo f(long x)

Eccoti un link per i tipi di dati primitivi in java :
http://download.oracle.com/javase/t.../datatypes.html

16-12-2010 13:32
Click Here to See the Profile for zack1988 Click here to Send zack1988 a Private Message Find more posts by zack1988 Add zack1988 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Paul442
.consigliere.

User info:
Registered: Nov 2006
Posts: 130 (0.02 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 13:34:28 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

grazie mille per il link...

22-12-2010 08:26
Click Here to See the Profile for Paul442 Click here to Send Paul442 a Private Message Find more posts by Paul442 Add Paul442 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
tyrdrummer
dsy moderator

User info:
Registered: Jun 2005
Posts: 487 (0.07 al dì)
Location: Milan
Corso: Com.Dig
Anno:
Time Online: 5 Days, 3:55:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by zack1988
potresti passarmi il testo del compito.

CASO 1:
A <- B (B estende A)
L'eredita è a senso "unico" il figlio prende le propietà dal padre e non il contrario.

Quindi in questo caso quando hai istanziato a : A a = new B();
facendo a.f(double) va in errore perchè la classe A non ha visibilità dei metodi e delle propietà di B, quindi non trovando il metodo f con parametro double.

Per poter accedere al metodo devi eseguire il casting:
B b = (B) a;

CASO 2:
B <- A (A estende B)
allora andava in errore quando tentavi di inizializzare
a = new B();


sinceramente non capisco perchè dici che l'ereditarietà è a senso unico, nel caso
a.f(double) c'è un metodo double nella classe B pronto perchè mi parli di classe A? Il compilatore vedendo il tipo dell'oggetto ovvero di tipo B non dovrebbe selezionare i metodi di B e quindi il relativo metodo double?

31-01-2011 16:01
Click Here to See the Profile for tyrdrummer Click here to Send tyrdrummer a Private Message Find more posts by tyrdrummer Add tyrdrummer to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
tyrdrummer
dsy moderator

User info:
Registered: Jun 2005
Posts: 487 (0.07 al dì)
Location: Milan
Corso: Com.Dig
Anno:
Time Online: 5 Days, 3:55:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

tutto ok ho capito

:)

31-01-2011 16:23
Click Here to See the Profile for tyrdrummer Click here to Send tyrdrummer a Private Message Find more posts by tyrdrummer Add tyrdrummer to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 12:29.    Post New Thread    Post A Reply
  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.038 seconds (84.59% PHP - 15.41% MySQL) con 25 query.