Logo Studenta

Examen Complementario Diseño SW

¡Estudia con miles de materiales!

Vista previa del material en texto

UNIVERSIDAD PERUANA LOS 
ANDES FACULTAD DE INGENIERÍA 
 
 
D ISEÑO DE SOFTWARE 
EXAMEN COMPLEMENTARIO 
 
 
APELLIDOS Y NOMBRES DEL ESTUDIANTE CICLO Y SECCION NOTA : 
 CARRASCO VERAMENDI SERGIO VI Letra Número 
 
CODIGO FECHA HORA DE INICO HORA DE TÉRMINO 
 M04464C 28/01/2021 
 
Pregunta Nº 01: De los principios SOLID en el Diseño de Software, explicar con un 
ejemplo el principio de Interface Segregation Principle (ISP) 
- Realizar un ejemplo en Visual C# (6 pts) 
Pregunta Nº 02: Del patrón de Diseño Observer: 
- Que principios de SOLID aplica. (3 Pts). 
- Implementar una solución utilizando el patrón en Visual C#. (7 Pts). 
SOLUCION: 
1. El principio de Interface Segregación Principle 
Que una clase nunca debe implementar una interfaz con métodos 
que no usará. Por lo que se deben evitar interfaces grandes, para 
no tener implementaciones innecesarias (clases con métodos 
vacíos que no se necesitan), también debe evitar soluciones a este 
principio, en donde se generan interfaces parciales de la interfaz, 
sin tomar en cuenta la necesidad concreta que define a esta 
interfaz. 
 
Ejemplo: 
 
 
Recomendaciones: 
Lee atentamente cada pregunta y responde completando tu respuesta, evita copiar que pueden invalidar tu respuesta. 
Duración de la evaluación: (120 minutos). Materiales equipos y/o instrumentos permitidos: PC 
 
 
1.- 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
 
namespace InterfaceSegregation 
{ 
 class Program 
 { 
 static void Main(string[] args) 
 { 
 MultiAvanzado avanzado = new MultiAvanzado(); 
 avanzado.Escanear(); 
 avanzado.Faxear(); 
 avanzado.Imprimir(); 
 avanzado.Telefono(); 
 
 Console.WriteLine("--------"); 
 
 Fax miFax = new Fax(); 
 miFax.Telefono(); 
 miFax.Faxear(); 
 miFax.Imprimir(); 
 
 Console.WriteLine("--------"); 
 
 MultiSencillo sencillo = new MultiSencillo(); 
 sencillo.Escanear(); 
 sencillo.Imprimir(); 
 //sencillo.Telefono(); //lanzara la excepcion 
 
 
 
 } 
 } 
} 
 
2,. 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
 
namespace InterfaceSegregation 
{ 
 class MultiAvanzado:IMultifuncional 
 { 
 public void Imprimir() 
 { 
 Console.WriteLine("Imprimo tu reporte"); 
 } 
 public void Escanear() 
 { 
 Console.WriteLine("Estoy escaneando un documento"); 
 } 
 public void Telefono() 
 { 
 Console.WriteLine("Te marco a un telefono"); 
 } 
 public void Faxear() 
 { 
 Console.WriteLine("Envio un fax"); 
 } 
 } 
} 
 
3.- 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
 
namespace InterfaceSegregation 
{ 
 class MultiSencillo:IMultifuncional 
 { 
 //necesitamos estos metodo 
 public void Imprimir() 
 { 
 Console.WriteLine("Imprimo tu documento"); 
 } 
 public void Escanear() 
 { 
 Console.WriteLine("Escaneo una fotografia"); 
 } 
 
 //estos metodos no lo necesitamos 
 //si no colocamos implementacion hay que pone excepcion 
 public void Telefono() 
 { 
 throw new NotImplementedException(); 
 } 
 public void Faxear() 
 { 
 throw new NotImplementedException(); 
 } 
 } 
} 
4.- 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
 
namespace InterfaceSegregation 
{ 
 class Fax:IMultifuncional 
 { 
 //no bemos forzado a implementar estos metodos 
 public void Imprimir() 
 { 
 Console.WriteLine("No tengo este servivcio"); 
 } 
 public void Escanear() 
 { 
 Console.WriteLine("No tengo este servicio"); 
 } 
 //Estos metodos si lo necesitamos 
 public void Telefono() 
 { 
 Console.WriteLine("Te marco a un telefono"); 
 } 
 public void Faxear() 
 { 
 Console.WriteLine("Envio un fax"); 
 } 
 
 } 
} 
 
2.- patrón Observer 
 Aplica el principio de responsabilidad única. Según este principio “una clase debería 
tener una, y solo una, razón para cambiar”. Es esto, precisamente, “razón para 
cambiar”. 
 
 
Observador (Interfaz IObserver) 
interface IObserver 
{ 
 void Update(SubjectEvent subjectEvent); 
} 
 
Sujeto (Interfaz ISubject) 
interface ISubject 
{ 
 void Subscribe(IObserver observer); 
 void Unsubscribe(IObserver observer); 
 void NotifyObservers(SubjectEvent subjectEvent); 
} 
 
Evento 
class SubjectEvent 
 { 
 public string EventType { get; set; } 
 public DateTime EventDate { get; set; } 
 } 
 
Clases concretas 
class ConsoleObserver : IObserver 
{ 
 public void Update(SubjectEvent subjectEvent) 
 { 
 Console.WriteLine("An event just happened!"); 
 Console.WriteLine("Event type: " + subjectEvent.EventType); 
 Console.WriteLine("Date: " + subjectEvent.EventDate); 
 } 
} 
 
sujeto concreto. 
 
class ProductService : ISubject 
{ 
 private readonly IList observers; 
 public ProductService() { 
 observers = new List(); 
 } 
 public void Subscribe(IObserver observer) { 
 observers.Add(observer); 
 } 
 
 public void Unsubscribe(IObserver observer) { 
 observers.Remove(observer); 
 } 
 
 public void AddProduct(string productName) { 
 //Business logic to validate and add a product. 
 var subjectEvent = new SubjectEvent { 
 EventType = "ProductAdded", 
 EventDate = DateTime.Now 
 }; 
 NotifyObservers(subjectEvent); 
 } 
 public void NotifyObservers(SubjectEvent subjectEvent) { 
 Console.WriteLine("Before notifying observers"); 
 foreach(IObserver observer in observers) { 
 observer.Update(subjectEvent); 
 } 
 Console.WriteLine("After notifying observers"); 
 } 
 }

Continuar navegando