Diapositivas de Politécnica sobre Programación Orientada a Objetos (POO). El Pdf explora el diseño orientado a objetos, los principios SOLID y conceptos como cohesión y acoplamiento, con ejemplos en Java. Es un material de Informática para Universidad.
Ver más58 páginas


Visualiza gratis el PDF completo
Regístrate para acceder al documento completo y transformarlo con la IA.
C 1Extensión VS Composición/Agregación
POO :: DOO 4 doo ADAPO inheritance composition aggregation User «key »-id : Integer «unique»-mobile : Integer -name : String -address : String -eMail : String -eMail : String -educationalLevel : String -educationalLevel : String 1 1 IVE AdvancedUser -eMail : String -educationalLevel : String «key »-id : Integer «unique»-mobile : Integer -name : String -address : String «key »-id : Integer «unique»-mobile : Integer -name : String -address : String NATIONI IMPENDI AdvancedUser AdvancedUser 0 .. 1 1 User UserPOO :: DOO
An 1POO :: DOO
Client +method( ) Singleton.getInstance(); single ton Singleton 1 -instance : Singleton 2 -Singleton() +getInstance() : Singleton 3 LIVER Se garantiza que una clase sólo tenga una instancia y se proporciona un acceso global a ella .D P Atributo privado estático de la propia clase. · Creación temprana (eager). 2 Constructor privado. 3 Método estático y público para devolver el atributo. · Creación perezosa (lazy) MPENDI nn TDPOO :: DOO
logger Logger -logs : String +Logger() +addLog( log : String ) +getLogs() : String +clear() Logger AD*PO solution Logger -logger : Logger -logs : String -Logger() +getLogger() : Logger +addLog( log : String ) +getLogs() : String +clear() Logger & Singleton IMPENDI nn T DSingleton APP-SHOP POO :: DOO
POLA DependencyInjector -dependencyInjector - -Dependency Injector() +getDependencyInjector() DependencyInjector NATIONI ENDI n TDCommand (Order)
command Invoker Order O -orders : Map 1 +execute() +name() : String +icon() +add( order : Order ) +invoker( String key ) +keys() 4 1 1 Order1 Order2 Order3 -receptor : Receptor1 -receptor : Receptor1 -receptor : Receptor2 +Order1(receptor : Receptor1) +execute () +Order2(receptor : Receptor1) +execute () +Order3( receptor ) +execute() Receptor1 this.receptor.action1(); +action1() +action2() 4 Receptor2 +action3() Se desacopla el objeto que invoca a la operación asociada, mediante un objeto. D P El invocador maneja un mapa de comandos, desconoce su tipo 2 Interface para desacoplar al invocador. · Se establece los métodos de un comando 3 Una clase por cada comando 4 Los receptores pueden estar compartidos entre comandos NATIONI IMPENDI TD nn 2 3POO :: Programación OO
console C CommandLineInterface D User user · help() · setUser() 1 1 I Command 1 1 1 1 void execute(String[] params) «default» String help() 7 1 commands 1 E Delimiters CListUsers C CreateUser C Login Help TECHNICA services ATIONI C View CUserService POLA String name() List params() List allowedRoles() String helpMessage() ELSIDAProgramación Orientada a Objetos
Programación imperativa: ¿Cómo ?. Abstracción, encapsulamiento, modularidad, jerarquía. Clases relacionadas mediante herencia, composición, agregación y asociación. Objetos con estado: los atributos. Unidad: Clases & Objetos.
UNIVER D*PO Programación declarativa: ¿ Qué ?. Basado en Funciones: funciones Lambda. Sin estado, sin orden y sin efectos colaterales. Valores inmutables: paso de parámetros por valor. Unidad: Función. NAI IMPENDI nn T DPOO :: DOO
public Integer function (String param) return Integer.valueOf(param); } { public void consumer(String p1, String p2) { System.out.println(p1 + p2); } public Boolean predicate(String value) value = value.trim(); return value.length() < 4; } { TECHNICA NATIONI IMPENDI M nn TD public String suplier() return " ... "; }
param -> Integer.valueOf(param) Integer :: valueOf (p1, p2) -> System.out.println(p1 + p2) (String p1, String p2) -> System.out.println(p1 + p2) value -> { value = value.trim(); return value.length() < 4; }; () ->" ... "
Consumer accept(T) · System.out :: println (item->) Function apply(T):R · item -> item +1 R Predicate test(T):Boolean · item -> item > 0 Supplier get(): T · ()->" ... " ... nn TPOO :: DOO
public static final List INTEGER_LIST = List.of(3, -2, 0, 4); public void consumer() { for (int i = 0; i < INTEGER_LIST.size(); i++) { //for i System.out.println(INTEGER_LIST.get(i)); } for (int item : INTEGER_LIST) { //for each System.out.println(item); } C ONI
INTEGER_LIST.stream().forEach(System.out :: println); //functional } DProgramación Funcional
public static final List INTEGER_LIST = List.of(3, -2, 0, 4); public void predicate() {// only positive values for (int item : INTEGER_LIST) { //for each if (item >= 0) { System.out.println(item); } } NATIONI T DPOO :: DOO
INTEGER_LIST.stream() //functional .filter(item -> item >= 0) .forEach(System.out :: println); }
public static final List STRING_LIST = List.of("3", "-2", "0", "4"); public void function() {// convierte a Integer, elimina 0 y *2 List result2 = new ArrayList<>(); for (String item : STRING_LIST) { //for each int intItem = Integer.parseInt(item); if (intItem != 0) { result2.add(intItem * 2); } } NATIONI 1PENDI TD nn }
List result = STRING_LIST.stream() //functional .map(Integer :: parseInt) .filter(item -> item != 0) .map(item -> item * 2) .toList();
public static final List STRING_LIST = List.of("3", "-2", "0", "4"); public void suplier() { List result = new ArrayList<>(); for (int i = 0; i < 10; i++) { //for i result.add(i * 2); } System.out.println(result); NATIONI 1PENDI } TDPOO :: DOO
List result2 = IntStream .range(0, 10) .map(value -> value * 2) .boxed() .toList(); System.out.println(result2);
public static final List INTEGER_LIST = List.of(3, -2, 0, 4); public void average() { int sum = 0; for (int number : INTEGER_LIST) { sum += number; } double average = (double) sum / INTEGER_LIST.size(); NATIONI T D
average = INTEGER_LIST.stream() .mapToDouble(Integer :: intValue) .average() .orElse Throw(); // Manejo de caso vacío }Java
list.stream(); IntStream.range(); Stream.of("1", "2" ... ); Stream.generate(); Stream.iterate(); DAD*POL .toList() toArray(Integer :: new) [a, b, c] TECHNICA NATIONI IMPENDI UNIVER nn TDPOO :: DOO
.filter(Predicate) .skip(long) .limit(long) QAD*POLA LIVER .distinct() NATIONI TECHNICA IMPENDI nn TD