[RISOLTO]Gof-Design patterns. Problema con diagrammi uml

Linguaggi di programmazione: php, perl, python, C, bash e tutti gli altri.
Avatar utente
Alkatron
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1248
Iscrizione: giovedì 16 aprile 2009, 13:26
Distribuzione: debian jessie 64
Contatti:

[RISOLTO]Gof-Design patterns. Problema con diagrammi uml

Messaggio da Alkatron »

Sto studiando questo libro, spero che qualcuno lo abbia studiato in quanto e un classico dell OOP (si trova facilmente googlando).
Design Patterns: Elements of Reusable Object-Oriented Software
Ho un problema con i diagrammi uml, prendendo per esempio la figura allegata, a quanto ho capito la freccia con la pallina rappresenta un associazione multipla e quindi maze giustamente mantiene piu riferimenti alle rooms (maze sa delle rooms ma le rooms non sanno di maze).
Quello che non capisco e lo stesso tipo di associazione tra room e mapsite che e una classe astratta...che senso ha?

Because the creational patterns are closely related, we’ll study all five of them together to highlight their similarities and differences. We’ll also use a common example—building a maze for a computer game— to illustrate their implementations. The maze and the game will vary slightly from pattern to pattern.
Sometimes the game will be simply to find your way out of a maze; in that case the player will probably only have a local view of the maze. Sometimes mazes contain problems to solve and dangers to overcome, and these games may provide a map of the part of the maze that has been explored.
We’ll ignore many details of what can be in a maze and whether a maze game has a single or multiple players. Instead, we’ll just focus on how mazes get created. We define a maze as a set of rooms. A room knows its neighbors; possible neighbors are another room, a wall, or a door to another room.
The classes Room, Door, and Wall define the components of the maze used in all our examples. We define only the parts of these classes that are important for creating a maze. We’ll ignore players, operations for displaying and wandering around in a maze, and other important functionality that isn’t relevant to building the maze.
The class MapSite is the common abstract class for all the components of a maze.
Each room has four sides.
The following diagram shows the relationships between these classes:
Allegati
Screenshot.png
Ultima modifica di Alkatron il venerdì 28 aprile 2017, 11:42, modificato 1 volta in totale.
Avatar utente
jepessen
Imperturbabile Insigne
Imperturbabile Insigne
Messaggi: 3569
Iscrizione: lunedì 26 dicembre 2005, 11:49
Desktop: KDevelop
Distribuzione: Ubuntu 20.04
Sesso: Maschile
Località: Somma Lombardo

Re: Gof-Design patterns. Problema con diagrammi uml

Messaggio da jepessen »

Beh, il diagramma parla chiaro...
E' presente una classe base/interfaccia chiamata MapSite, che sono presumibilmente gli oggetti della scena (o livello, quel che e').
L'interfaccia definisce dei metodi base che sono in comune per tutti gli oggetti del livello, in questo caso Enter.
Poi ci sono le realizzazioni dell'interfaccia, quindi Room, Wall e Door sono oggetti che ereditano da MapSite, e di conseguenza implementano la loro versione di Enter.
Una Room ha delle pareti, e presumibilmente queste pareti confinano con altri oggetti di tipo MapSite. Una Room quindi puo' avere altri oggetti di tipo MapSite ai lati.

Supponiamo che Room sia una casella quadrata. Ai lati puo' avere quindi un'altra Room, ottenendo quindi una stanza con superficie doppia. Puo' avere un Wall, o puo' avere una porta. In questo modo e' possibile creare stanze di diverse dimensioni e con diverse porte.

In pratica e' un pattern Composite per la creazione di livelli.

Poi c'e' il maze che e' un insieme di stanze.

In definitiva, il maze e' formato da diverse stanze, ed ogni stanza e' formata da un insieme di stanze (per aumentare la superficie), muri e porte.

Se un domani volessimo aggiungere anche delle finestre, basta creare la classe Window che eredita da MapSite, e per il resto del codice sarebbe tutto trasparente.
Compiz l'ha creato Chuck Norris quando ha colpito un computer con un calcio rotante.
http://www.renderosity.com/mod/gallery/ ... e=Jepessen
http://jepessen.wordpress.com/
Avatar utente
Alkatron
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1248
Iscrizione: giovedì 16 aprile 2009, 13:26
Distribuzione: debian jessie 64
Contatti:

Re: Gof-Design patterns. Problema con diagrammi uml

Messaggio da Alkatron »

Grazie
Scrivi risposta

Ritorna a “Programmazione”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 2 ospiti