Author Topic: sequence diagrams  (Read 1289 times)

rescobar

  • EA User
  • **
  • Posts: 69
  • Karma: +0/-0
  • Viva Bolivia
    • View Profile
sequence diagrams
« on: April 01, 2003, 07:48:57 am »
Please somebody could tell me how to construct a "good" sequence diagram from real code?.
For example, in the following code (part of a form class code), how could I represent all the messages?
This is a form with a TabControl. It inlcudes a grid. Also references to a webservice (persistence service).
I'm very confused with the sequence diagrams. The class diagrams are easy and clear and there is no problem with them.
Maybe my approach is wrong?
Thanks to all

Imports System.Text

Public Class frmClientes
 Inherits System.Windows.Forms.Form

 Private pLim As clsLimpiarPantallas
 Private mdsCliente As cpd02.dsClientes01
 Protected WithEvents ds As New cpd02.dsClientes01() 'para todos los datos
 Private ws As New cpd02.ClientesWS()
 Private WithEvents dgRUC As New clsGridRUC()  'tablas que serán leidas de la base de datos
 Private dsI As New cpd02.dsClientes01() 'para la grid

 Private mModoClientes As Integer
 Private mModoRUC As Integer
 Private mCodTipoDocCI As Integer
 Private tbTipoDoc As String = "TipoDoc"
 Private tbLugarEmision As String = "LugarEmision"
 Private tbTiposPersona As String = "TiposPersona"
 Private tbEstadoCivil As String = "EstadoCivil"
 Private tbCaedec As String = "Caedec"
 Private tbProfesiones As String = "Profesiones"
 Private tbSexo As String = "Sexo"
 Private tbTiposVivienda As String = "TiposVivienda"
 Private tbClientes As String = "Clientes"
 Private tbRucCliente As String = "RUCCliente"

Private Sub frmClientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ds.Merge(ws.GetDatos(String.Empty, tbTipoDoc))
   ds.Merge(ws.GetDatos(String.Empty, tbLugarEmision))
   ds.Merge(ws.GetDatos(String.Empty, tbTiposPersona))
   ds.Merge(ws.GetDatos(String.Empty, tbEstadoCivil))
   ds.Merge(ws.GetDatos(String.Empty, tbCaedec))
   ds.Merge(ws.GetDatos(String.Empty, tbProfesiones))
   ds.Merge(ws.GetDatos(String.Empty, tbSexo))
   ds.Merge(ws.GetDatos(String.Empty, tbTiposVivienda))

   'traemos el parámetro de codigo de Carnet de Identidad en la Tabla TipoDoc
   'La clave de este parámetro es 2
   ds.Merge(ws.GetValorUnParam(2))
   mCodTipoDocCI = CInt(ds.Parametros.Rows(0)(2))

   'combo de Tipo de Documento
   Me.cmbTipoDoc.DataSource = ds.TipoDoc.DefaultView
   Me.cmbTipoDoc.DisplayMember = ds.TipoDoc.DescrTipoDocColumn.ToString
   Me.cmbTipoDoc.ValueMember = ds.TipoDoc.CodTipoDocColumn.ToString
   Me.cmbTipoDoc.SelectedValue = mCodTipoDocCI

   'combo de Lugar de Emisión
   Me.cmbLugarEmision.DataSource = ds.LugarEmision.DefaultView
   ds.LugarEmision.DefaultView.Sort = "CodLugarEmision"
   Me.cmbLugarEmision.DisplayMember = ds.LugarEmision.DescrLugarEmisionColumn.ToString
   Me.cmbLugarEmision.ValueMember = ds.LugarEmision.CodLugarEmisionColumn.ToString
   Me.cmbLugarEmision.SelectedIndex = 0
   Me.cmbLugarEmision.Visible = True

   'combo de Tipos de Persona
   Me.cmbTiposPersona.DataSource = ds.TiposPersona.DefaultView
   ds.TiposPersona.DefaultView.Sort = "CodTiposPersona"
   Me.cmbTiposPersona.DisplayMember = ds.TiposPersona.DescrTiposPersonaColumn.ToString
   Me.cmbTiposPersona.ValueMember = ds.TiposPersona.CodTiposPersonaColumn.ToString

   'combo de Estado Civil
   Me.cmbEstadoCivil.DataSource = ds.EstadoCivil.DefaultView
   ds.EstadoCivil.DefaultView.Sort = "CodEstadoCivil"
   Me.cmbEstadoCivil.DisplayMember = ds.EstadoCivil.DescrEstadoCivilColumn.ToString
   Me.cmbEstadoCivil.ValueMember = ds.EstadoCivil.CodEstadoCivilColumn.ToString

   'combo de Caedec
   Me.cmbCaedec.DataSource = ds.Caedec.DefaultView
   ds.Caedec.DefaultView.Sort = "DescrCaedec"
   Me.cmbCaedec.DisplayMember = ds.Caedec.DescrCaedecColumn.ToString
   Me.cmbCaedec.ValueMember = ds.Caedec.CodCAEDECColumn.ToString

   'combo de Profesiones
   Me.cmbProfesiones.DataSource = ds.Profesiones.DefaultView
   ds.Profesiones.DefaultView.Sort = "DescrProfesiones"
   Me.cmbProfesiones.DisplayMember = ds.Profesiones.DescrProfesionesColumn.ToString
   Me.cmbProfesiones.ValueMember = ds.Profesiones.CodProfesionesColumn.ToString

   'combo de Sexo
   Me.cmbSexo.DataSource = ds.Sexo.DefaultView
   ds.Sexo.DefaultView.Sort = "DescrSexo"
   Me.cmbSexo.DisplayMember = ds.Sexo.DescrSexoColumn.ToString
   Me.cmbSexo.ValueMember = ds.Sexo.CodSexoColumn.ToString

   'combo de TiposVivienda
   Me.cmbTiposVivienda.DataSource = ds.TiposVivienda.DefaultView
   ds.TiposVivienda.DefaultView.Sort = "CodTiposVivienda"
   Me.cmbTiposVivienda.DisplayMember = ds.TiposVivienda.DescrTiposViviendaColumn.ToString
   Me.cmbTiposVivienda.ValueMember = ds.TiposVivienda.CodTiposViviendaColumn.ToString

   'habilitamos solo el tab de ingreso de datos del cliente
   'Me.TabControl1.TabPages.Item(0).Visible = True
   Dim ii As Integer
   For ii = 1 To 4
     Me.TabControl1.TabPages.Item(ii).Enabled = False
   Next
   Me.txtCodClienteRUC.BackColor = System.Drawing.Color.White
   Me.txtNombreClienteRUC.BackColor = System.Drawing.Color.White

   'añadimos la grid de RUC
   dgRUC.Visible = False
   Me.TabControl1.TabPages(1).Controls.Add(dgRUC)
   'preparamos el tab de acuerdo al estado
   pLim = New clsLimpiarPantallas()
   pLim.preparaTabRUC(Me)
   'El texto del código en blanco aunque esté deshabilitado
   Me.txtCodigo.BackColor = System.Drawing.Color.White

   'habilitamos botones de acuerdo al modo mInsUpd

   If Me.modoClientes = 0 Then
     Me.btnAdd.Enabled = True
     Me.btnModifCliente.Enabled = False
   Else
     Me.btnAdd.Enabled = False
     Me.btnModifCliente.Enabled = True
   End If

 End Sub

 Private Sub cmbTipoDoc_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbTipoDoc.SelectedValueChanged
   Dim aa As String = Me.cmbTipoDoc.SelectedValue.GetType.ToString
   If Me.cmbTipoDoc.SelectedValue.GetType.ToString <> "System.Data.DataRowView" Then
     If Me.cmbTipoDoc.SelectedValue = mCodTipoDocCI Then
       Me.cmbLugarEmision.Visible = True
     Else
       Me.cmbLugarEmision.Visible = False
     End If
   End If
 End Sub

 Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
   'validamos los campos
   Dim mResul As New ArrayList()
   Dim mValid As New clsValidacion(Me)
   mResul = mValid.ValidarClientes
   If mResul.Count > 0 Then
     Dim sRes As New StringBuilder()
     sRes.Remove(0, sRes.Length)
     Dim mEnum As System.Collections.IEnumerator = mResul.GetEnumerator
     sRes.Append("Por favor corrija los siguientes errores:" & ControlChars.CrLf & ControlChars.CrLf)
     While mEnum.MoveNext()
       sRes.Append(mEnum.Current & ControlChars.CrLf)
     End While
     MessageBox.Show(sRes.ToString, "Errores", MessageBoxButtons.OK, MessageBoxIcon.Error)
     Exit Sub
   End If

   'paso la validación nos creamos una row de la tabla clientes con los datos
   'de la pantalla. Este dataset es nuevo para que solo viajen los datos de la tabla clientes
   'y no los que hemos llenado antes a ds.
   Dim dr As cpd02.dsClientes01.ClientesRow
   dr = dsI.Clientes.NewRow
   dr.ApellidoCasada = Me.txtApellidoCasada.Text
   dr.Celular = Me.txtCelular.Text
   dr.CodCAEDEC = Me.cmbCaedec.SelectedValue
   dr.CodClientes = 1
   dr.CodEstadoCivil = Me.cmbEstadoCivil.SelectedValue
   dr.CodLugarEmision = Me.cmbLugarEmision.SelectedValue
   dr.CodProfesiones = Me.cmbProfesiones.SelectedValue
   dr.CodSexo = Me.cmbSexo.SelectedValue
   dr.CodTipoDoc = Me.cmbTipoDoc.SelectedValue
   dr.CodTiposPersona = Me.cmbTiposPersona.SelectedValue
   dr.CodTiposVivienda = Me.cmbTiposVivienda.SelectedValue
   dr.EMail = Me.txtEMail.Text
   dr.EstacionMod = System.Net.Dns.GetHostName
   dr.FechaMod = DateTime.Now
   dr.LugarNacimiento = Me.txtLugarNacimiento.Text
   dr.FechaNacimiento = Me.dtpFechaNacimiento.Value
   dr.NumCarnetId = Me.txtNumDocumento.Text
   If Me.txtDependientes.Text <> String.Empty And IsNumeric(Me.txtDependientes.Text) Then
     dr.NumDependientes = Me.txtDependientes.Text
   End If
   dr.PrimerApellido = Me.txtPrimerApellido.Text
   dr.PrimerNombre = Me.txtPrimerNombre.Text
   dr.SegundoApellido = Me.txtSegundoApellido.Text
   dr.SegundoNombre = Me.txtSegundoNombre.Text
   dr.UsuarioMod = clsDatosUsuario.usuario
   dsI.Clientes.Rows.Add(dr)
   Try
     dsI.Merge(ws.UpdDatos(dsI, tbClientes))
     dsI.AcceptChanges()
     Me.txtCodigo.Text = dsI.Clientes.Rows(0)(0)
     dsI.Clear()
     Dim ii As Integer
     For ii = 1 To 4
       Me.TabControl1.TabPages.Item(ii).Enabled = True
     Next
     MessageBox.Show("Se insertó el registro con éxito", "Inserción", MessageBoxButtons.OK, MessageBoxIcon.Information)
   Catch e1 As Exception
     MessageBox.Show("Falla en la actualización de la base de datos." _
             & ControlChars.CrLf & ControlChars.CrLf & _
             e1.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try


 End Sub

 End Class
Sergio Escobar
rescobar@puntoinformatico.com

kevinimnotspacey

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • not spacey, well... sometimes.
    • View Profile
Re: sequence diagrams
« Reply #1 on: April 16, 2003, 03:09:56 pm »
Remember that sequence diagrams depict what goes on between objects.  you're code depicts a single class, whereas a sequence diagram would depict messages sent between instances of the class you gave and instances of other classes that it interacts with.

You wouldn't depict all the internal details such as setting all your properties and filling combo boxes, etc...

hopes this helps!

:: ! spacey ::
:: ! spacey ::

rescobar

  • EA User
  • **
  • Posts: 69
  • Karma: +0/-0
  • Viva Bolivia
    • View Profile
Re: sequence diagrams
« Reply #2 on: April 17, 2003, 11:15:15 am »
Anyway if you are a "purist" you should include all abjects in the sequence diagramam.

How do you think about a VS.NET IDE software design and
modeling all objects in .NET?
Where do you think is the "mid-point" between a good modeling practices and rapid development?
What do you think is the "correct" methodology?

I do the following:

Vision
Requirements
Architecture
Use Cases
Analysis Diagramas for Use Cases
DataBase modeling (using SQLServer 2000 diagrams)
Reverse database into Model
Programming using IDE
Reverse programs into Model
Refine code and model in a iterative manner.
Every relevant Use case should have at least: Analysis Diagram,
Sequence Diagram and Class Diagram
What do you think?
Thanks in advance
Sergio Escobar
rescobar@puntoinformatico.com

kevinimnotspacey

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • not spacey, well... sometimes.
    • View Profile
Re: sequence diagrams
« Reply #3 on: April 17, 2003, 12:22:55 pm »
Hello, I do consider myself kind of a "purist" / "code-nazi", and understand that this can be a good and bad thing ;).

As far as a .NET type IDE for modelling... I don't think its a really good idea.  I'm biased in that I don't like the .NET IDE. I'd much prefer to configure the builds, documentation and unit tests using NAnt.  The .NET IDE tries to do way too much and can impede good software development practices.

Good modelling speeds up development, so I think it works well, even in a RAD environment.  The question then becomes: "do it now in a model, or do it later in code", I don't think modelling really adds much to your tasks.  But I understand where you're coming from, you must avoid analysis paralysis.  And so I think you have to depend on experience, or management yelling at you to move on ;).

There is no "correct" methodology.  I prefer to adhere to UML as the toolset and strict OO guidelines for design.  The methodology might look something like:

- Gather requirements
- Write use cases
- Draw sequence diagrams
- Create Classes
- Fill in class stubs
- Reverse code back into diagrams

With each step being iterated through the whole process.  The first time you write a use case or draw a sequence diagram, you're not going to get it right, and these documents are never "complete".  So as you're doing the classes, you may need to change sequences or use cases, or new requirements may come up.

The process and the tools that you use from UML will totally depend on what kind of application you're designing/architecting, how complex it is, needs to interface with other systems, needs for other systems to interface with it, needs for pluggable components, needs for multiple user interfaces, etc...

Sorry for the long post! hope this helps :)
:: ! spacey ::