Final keyword are used in java for three purpose;
1. Final keyword is used in java to make variable constant
2. Final keyword restrict method overriding
3. It used to restrict Inheritance
http://www.tutorial4us.com/java/java-final-keyword
C++ allows the common function to be made friendly with both the classes, thereby allowing the function to have access to the private data of these classes. Such a function need not be a member of any of these classes.
The document discusses object-oriented programming languages like C++, Smalltalk, and Java. It covers the basic concepts of object-oriented programming including objects, classes, encapsulation, inheritance, and polymorphism. Key points about each language are provided, such as C++ being an extension of C and introducing classes, Smalltalk being one of the earliest languages to support OOP, and Java combining elements of C++ and Smalltalk. Sample code in each language is also shown.
This document discusses various methods for styling colors and backgrounds in CSS, including:
1) Using named color values or RGB, HSL, and RGBa values to specify foreground and background colors.
2) Applying background images, adjusting their position, size, and repetition.
3) Creating gradients using functions like linear-gradient() and radial-gradient().
4) Attaching external style sheets to HTML documents using <link> tags or @import rules.
Final keyword are used in java for three purpose;
1. Final keyword is used in java to make variable constant
2. Final keyword restrict method overriding
3. It used to restrict Inheritance
http://www.tutorial4us.com/java/java-final-keyword
C++ allows the common function to be made friendly with both the classes, thereby allowing the function to have access to the private data of these classes. Such a function need not be a member of any of these classes.
The document discusses object-oriented programming languages like C++, Smalltalk, and Java. It covers the basic concepts of object-oriented programming including objects, classes, encapsulation, inheritance, and polymorphism. Key points about each language are provided, such as C++ being an extension of C and introducing classes, Smalltalk being one of the earliest languages to support OOP, and Java combining elements of C++ and Smalltalk. Sample code in each language is also shown.
This document discusses various methods for styling colors and backgrounds in CSS, including:
1) Using named color values or RGB, HSL, and RGBa values to specify foreground and background colors.
2) Applying background images, adjusting their position, size, and repetition.
3) Creating gradients using functions like linear-gradient() and radial-gradient().
4) Attaching external style sheets to HTML documents using <link> tags or @import rules.
In given slide ITVoyagers has tried to explain the concept of constructor in Java. We have used very simple language to make this silde.
We have used few examples to explain the concept.
We cover following points.
- Why we need constructor?
- Use of constructor.
- Type of constructor.
- Examples
- Rules for constructor.
- Advantages of constructor.
......................................................
Hope you will like it.
ITVoyagers is trying to make slides of topics related to IT/CS.
Please visit our blog - itvoyagers.in
In these slides i have explained an important design pattern that is "singleton pattern".
slides includes everything required about it, from definition to implementation and also different ways to achieve it according to situation and requirements.
Este documento describe la herencia simple y múltiple en programación orientada a objetos. Explica que la herencia simple permite que una clase herede los atributos y métodos de una superclase. Mientras que C# no permite la herencia múltiple, sí permite que clases derivadas hereden de otras clases derivadas a través de la herencia simple. También provee consejos sobre la clase Object y la invocación de constructores en herencia.
The document discusses object-oriented programming (OOP) concepts including encapsulation, abstraction, inheritance, polymorphism, and classes. It explains that OOP is a programming paradigm that uses objects which contain both data and code. Classes define the data and behavior of objects, and can be reused, extended, and abstracted to simplify programming and code maintenance. Inheritance allows new classes to inherit attributes and behaviors from existing classes. Polymorphism enables the same function to operate in different ways depending on the object it is acting upon.
The document discusses Java's Collections framework. It provides an overview of Collections and their benefits, describes the core Collections interfaces like Collection, Set, List, Queue, Map, SortedSet and SortedMap. It also discusses common operations, implementations, iteration, algorithms and thread safety considerations for Collections.
Public access allows classes, methods, and fields to be accessed from any other class. Private access restricts access to only within the declared class. Protected access allows subclasses in other packages or classes within the package to access protected members. The default access level is equivalent to no access modifier specified, making classes only visible to other classes in the same package.
The document discusses different approaches to object-oriented programming in JavaScript, including classical and prototypal inheritance, constructor functions, and the prototype property. It explains how prototypal inheritance works by linking objects together through their internal prototype properties. Constructor functions and the new operator allow simulating classical inheritance by establishing prototype links. Various design patterns are also covered, such as public/privileged methods, singletons, modules, and parasitic inheritance.
CSS inheritance allows descendant elements to inherit certain CSS properties from their ancestor elements. This helps reduce the amount of CSS code needed and makes styling easier. Key properties like color, font-size, and font-family are inherited by default. Font-size inheritance works by inheriting the calculated pixel value rather than the actual percentage or EM value. Understanding inheritance is important for efficiently writing CSS with less code.
RESTful web services with Groovy on Grails by Vugar SuleymanovVuqar Suleymanov
This document discusses RESTful web services and provides examples of implementing RESTful APIs with Groovy and Grails. It defines RESTful web services and compares them to SOAP web services. It then demonstrates creating RESTful resources and controllers in Grails that support CRUD operations and return JSON or XML responses. Examples of testing the RESTful APIs using a web browser and Postman are also included.
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Edureka!
This tutorial on Selenium will help you understand what is Page Object Model (POM) and Page Factory? You will also understand why POM design pattern should be followed for creating your test case.
The following topics will be covered in this session:
1. Why Use Page Object Model(POM)?
2. What Is Page Object Model?
3. What Is Page Factory?
4. Demo: Creating POM & Page Factory
This document provides a summary of an introductory presentation on advanced JavaScript concepts including closures, prototypes, inheritance, and more. The presentation covers object literals and arrays, functions as objects, constructors and the this keyword, prototypes and the prototype chain, classical and prototypal inheritance, scope, and closures. Examples are provided to demonstrate each concept.
Abstraction is a process by which concepts are derived from the usage and classification of literal ("real" or "concrete") concepts.
Abstraction is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category.
This document discusses nested classes in Java. It defines nested classes as classes defined within other classes. There are two main types - non-static nested classes and static nested classes. Non-static nested classes can access private members of the outer class and require an outer class instance, while static nested classes behave like regular classes and do not require an outer class instance. The document covers the different types of non-static nested classes and provides examples to illustrate their usage and properties. It also compares static and non-static nested classes and discusses the advantages and disadvantages of using nested classes.
HTML5, CSS, JavaScript Style guide and coding conventionsKnoldus Inc.
Coding conventions are style guidelines for any programming language. As, we are growing ourselves rapidly in learning new technology, the need for learning of the coding standards and conventions for the same language also arises.
So, here let us try to learn some coding guidelines for few frontend languages.
eact is a library for building HTML user interfaces. It is the "view" in a Model-View-Controller application. Created by the UI wizards at Facebook, top websites like Instagram, Netflix, Airbnb, Bleacher Report and Feedly use it. React is the 6th most starred project on GitHub and grows more popular every day.
In this two-day workshop, we will introduce you to React. On the first day, we will work through a series of increasingly more complicated tutorial exercises. Along the way, we will explain concepts like JSX, immutability, statefulness, one-way data flow, components, and virtual DOM.
With the basics out of the way, we will spend the second-day building a complex application which will put React through its paces and give us a chance to explore most of its features. Then we will learn how to think in React. We will show you how to go from design to components to working application. We will wrap the weekend with a quick preview of React Native, which allows you to use your React skills to create cross-platform mobile apps.
CSS Grid provides a two-dimensional grid system for page layout, allowing elements to be positioned in rows and columns. Some key advantages of CSS Grid include having full control over page layout without needing additional HTML containers, and the ability to easily create complex column-based and row-based layouts. CSS Grid terminology includes grid container, grid items, grid lines, grid cells, tracks and areas. Properties like grid-template-columns, grid-template-rows and grid-area can be used to define the grid structure and position items.
Nested classes allow one class to be defined within another, enabling inner classes to access members of the outer class. There are several types of nested classes: inner classes that can be member, anonymous, or local; and static nested classes. Member inner classes can access outer class members and be invoked from within or outside the outer class. Anonymous inner classes have no name and are created from an abstract class or interface. Local inner classes exist only within a method. Static nested classes can access static members of the outer class but not instance members.
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
This document provides an overview of type conversion and regular expressions in JavaScript. It discusses how JavaScript variables can be converted between different data types either automatically or using functions. It covers converting between numbers, strings, booleans, and dates. It also provides an introduction to regular expressions including patterns, modifiers, and examples of using regular expression methods like exec(), test(), search(), split(), and replace() on strings. The document includes exercises for readers to practice these concepts.
Laravel is a popular PHP web framework created by Taylor Otwell in 2011. It follows the MVC pattern and simplifies development with modular structure, elegant syntax, and built-in features like routing, middleware, Blade templating, Eloquent ORM, and Artisan CLI. Laravel has a large community and is easy to learn and use due to its simplicity, modularity, and extensive built-in functionality that helps developers build cleaner code more efficiently.
In given slide ITVoyagers has tried to explain the concept of constructor in Java. We have used very simple language to make this silde.
We have used few examples to explain the concept.
We cover following points.
- Why we need constructor?
- Use of constructor.
- Type of constructor.
- Examples
- Rules for constructor.
- Advantages of constructor.
......................................................
Hope you will like it.
ITVoyagers is trying to make slides of topics related to IT/CS.
Please visit our blog - itvoyagers.in
In these slides i have explained an important design pattern that is "singleton pattern".
slides includes everything required about it, from definition to implementation and also different ways to achieve it according to situation and requirements.
Este documento describe la herencia simple y múltiple en programación orientada a objetos. Explica que la herencia simple permite que una clase herede los atributos y métodos de una superclase. Mientras que C# no permite la herencia múltiple, sí permite que clases derivadas hereden de otras clases derivadas a través de la herencia simple. También provee consejos sobre la clase Object y la invocación de constructores en herencia.
The document discusses object-oriented programming (OOP) concepts including encapsulation, abstraction, inheritance, polymorphism, and classes. It explains that OOP is a programming paradigm that uses objects which contain both data and code. Classes define the data and behavior of objects, and can be reused, extended, and abstracted to simplify programming and code maintenance. Inheritance allows new classes to inherit attributes and behaviors from existing classes. Polymorphism enables the same function to operate in different ways depending on the object it is acting upon.
The document discusses Java's Collections framework. It provides an overview of Collections and their benefits, describes the core Collections interfaces like Collection, Set, List, Queue, Map, SortedSet and SortedMap. It also discusses common operations, implementations, iteration, algorithms and thread safety considerations for Collections.
Public access allows classes, methods, and fields to be accessed from any other class. Private access restricts access to only within the declared class. Protected access allows subclasses in other packages or classes within the package to access protected members. The default access level is equivalent to no access modifier specified, making classes only visible to other classes in the same package.
The document discusses different approaches to object-oriented programming in JavaScript, including classical and prototypal inheritance, constructor functions, and the prototype property. It explains how prototypal inheritance works by linking objects together through their internal prototype properties. Constructor functions and the new operator allow simulating classical inheritance by establishing prototype links. Various design patterns are also covered, such as public/privileged methods, singletons, modules, and parasitic inheritance.
CSS inheritance allows descendant elements to inherit certain CSS properties from their ancestor elements. This helps reduce the amount of CSS code needed and makes styling easier. Key properties like color, font-size, and font-family are inherited by default. Font-size inheritance works by inheriting the calculated pixel value rather than the actual percentage or EM value. Understanding inheritance is important for efficiently writing CSS with less code.
RESTful web services with Groovy on Grails by Vugar SuleymanovVuqar Suleymanov
This document discusses RESTful web services and provides examples of implementing RESTful APIs with Groovy and Grails. It defines RESTful web services and compares them to SOAP web services. It then demonstrates creating RESTful resources and controllers in Grails that support CRUD operations and return JSON or XML responses. Examples of testing the RESTful APIs using a web browser and Postman are also included.
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Edureka!
This tutorial on Selenium will help you understand what is Page Object Model (POM) and Page Factory? You will also understand why POM design pattern should be followed for creating your test case.
The following topics will be covered in this session:
1. Why Use Page Object Model(POM)?
2. What Is Page Object Model?
3. What Is Page Factory?
4. Demo: Creating POM & Page Factory
This document provides a summary of an introductory presentation on advanced JavaScript concepts including closures, prototypes, inheritance, and more. The presentation covers object literals and arrays, functions as objects, constructors and the this keyword, prototypes and the prototype chain, classical and prototypal inheritance, scope, and closures. Examples are provided to demonstrate each concept.
Abstraction is a process by which concepts are derived from the usage and classification of literal ("real" or "concrete") concepts.
Abstraction is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category.
This document discusses nested classes in Java. It defines nested classes as classes defined within other classes. There are two main types - non-static nested classes and static nested classes. Non-static nested classes can access private members of the outer class and require an outer class instance, while static nested classes behave like regular classes and do not require an outer class instance. The document covers the different types of non-static nested classes and provides examples to illustrate their usage and properties. It also compares static and non-static nested classes and discusses the advantages and disadvantages of using nested classes.
HTML5, CSS, JavaScript Style guide and coding conventionsKnoldus Inc.
Coding conventions are style guidelines for any programming language. As, we are growing ourselves rapidly in learning new technology, the need for learning of the coding standards and conventions for the same language also arises.
So, here let us try to learn some coding guidelines for few frontend languages.
eact is a library for building HTML user interfaces. It is the "view" in a Model-View-Controller application. Created by the UI wizards at Facebook, top websites like Instagram, Netflix, Airbnb, Bleacher Report and Feedly use it. React is the 6th most starred project on GitHub and grows more popular every day.
In this two-day workshop, we will introduce you to React. On the first day, we will work through a series of increasingly more complicated tutorial exercises. Along the way, we will explain concepts like JSX, immutability, statefulness, one-way data flow, components, and virtual DOM.
With the basics out of the way, we will spend the second-day building a complex application which will put React through its paces and give us a chance to explore most of its features. Then we will learn how to think in React. We will show you how to go from design to components to working application. We will wrap the weekend with a quick preview of React Native, which allows you to use your React skills to create cross-platform mobile apps.
CSS Grid provides a two-dimensional grid system for page layout, allowing elements to be positioned in rows and columns. Some key advantages of CSS Grid include having full control over page layout without needing additional HTML containers, and the ability to easily create complex column-based and row-based layouts. CSS Grid terminology includes grid container, grid items, grid lines, grid cells, tracks and areas. Properties like grid-template-columns, grid-template-rows and grid-area can be used to define the grid structure and position items.
Nested classes allow one class to be defined within another, enabling inner classes to access members of the outer class. There are several types of nested classes: inner classes that can be member, anonymous, or local; and static nested classes. Member inner classes can access outer class members and be invoked from within or outside the outer class. Anonymous inner classes have no name and are created from an abstract class or interface. Local inner classes exist only within a method. Static nested classes can access static members of the outer class but not instance members.
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
This document provides an overview of type conversion and regular expressions in JavaScript. It discusses how JavaScript variables can be converted between different data types either automatically or using functions. It covers converting between numbers, strings, booleans, and dates. It also provides an introduction to regular expressions including patterns, modifiers, and examples of using regular expression methods like exec(), test(), search(), split(), and replace() on strings. The document includes exercises for readers to practice these concepts.
Laravel is a popular PHP web framework created by Taylor Otwell in 2011. It follows the MVC pattern and simplifies development with modular structure, elegant syntax, and built-in features like routing, middleware, Blade templating, Eloquent ORM, and Artisan CLI. Laravel has a large community and is easy to learn and use due to its simplicity, modularity, and extensive built-in functionality that helps developers build cleaner code more efficiently.
Inheritance allows one class to inherit properties from another class called the base or super class. The new class is called the derived or sub-class. There are different types of inheritance like hierarchical and multi-level inheritance. The visibility of members of the base class depends on whether the inheritance is public, private or protected.
This document provides an overview of inheritance in object-oriented programming. It defines inheritance as a child class automatically inheriting variables and methods from its parent class. Benefits include reusability, where behaviors are defined once in the parent class and shared by all subclasses. The document discusses how to derive a subclass using the extends keyword, what subclasses can do with inherited and new fields and methods, and how constructors are called following the constructor calling chain. It also covers overriding and hiding methods and fields, type casting between subclasses and superclasses, and final classes and methods that cannot be extended or overridden.
Inheritance allows one class to inherit attributes and behaviors from another existing class. This helps with code reuse by extending an existing class without modifying it. A derived class inherits from a base class, and any changes to the base class will also affect the derived classes. Abstract classes define common behaviors for other classes to inherit from but cannot be instantiated themselves, instead forcing subclasses to implement abstract methods.
This document discusses types of inheritance in object-oriented programming including single, multilevel, multiple, hierarchical, and hybrid inheritance. It provides code examples and explanations of:
- Single, multilevel, multiple, hierarchical, and hybrid inheritance structures
- Access specifiers for base and derived classes and their effects
- Calling base class constructors from derived class constructors
- The virtual keyword and dynamic binding in inheritance
The document contains code examples demonstrating inheritance concepts like defining base and derived classes, accessing members of base classes, and calling base class constructors from derived classes. It also provides explanations of multilevel, multiple, and hybrid inheritance with diagrams.
Here, class PQR contains an object of class ABC as its data member. So class PQR contains class ABC through object ob1. This is an example of containership relationship between classes in OOP.
This document discusses inheritance in Java. It defines inheritance as allowing new classes to reuse properties of existing classes. There are different types of inheritance including single, multilevel, and hierarchical. Key concepts covered include defining subclasses using the extends keyword, using the super keyword to call parent constructors and access parent members, overriding methods, abstract classes and methods, and using the final keyword to prevent overriding or inheritance.
jQuery è un framework javascript che permette di semplificare la scrittura di codice javascript, facilitando l'iterazione con gli elementi della pagina (controlli, stili, eventi, animazioni, ...), e permettendo di aumentare la user experience delle applicazioni, riducendone al tempo stesso la complessità di scrittura. Vista la sua diffusione e potenza, è stato anche incluso nei project templete di Visual Studio. In questa sessione vedremo cos'è jQuery, e scopriremo le potenzialità e funzionalità che offre, verificando se il motto "write less do more" sia vero o meno.
Django: utilizzo avanzato e nuove funzionalitàskam
Django è uno dei framework web più apprezzati e utilizzati dalla comunità Python (e non solo).
I suoi punti di forza sono rappresentati dal suo utilizzo rapido e intuitivo, l'ottima documentazione e una larga comunità di sviluppatori ed utilizzatori.
A più di un anno di distanza dal rilascio della versione 0.96 le feature e i miglioramenti introdotti sono stati molti.
La presentazione mostra alcune di queste novità e l'utilizzo avanzato di alcuni componenti del framework.
In questa sessione vedremo come realizzare un Data Access Layer basato su una implementazione del Repository pattern ed in grado di essere interrogabile mediante query LINQ, eventualmente delegate ad O/RM quali Entity Framework e/o NHibernate. Vedremo inoltre come fare utilizzo dei Code Contracts del FX4 per specificare "una tantum" le regole comuni a tutti i repository di un Domain Model.
1. La Programmazione Orientata agli Oggetti (O.O.P.) Object-Oriented Programming
2. Programmazione imperativa algoritmo si basa sul concetto di : Sappiamo che la Insieme di istruzioni che a partire dai dati di input permettono di ottenere dei risultati in output
3.
4. La Programmazione si fonda invece sul concetto di : orientata agli oggetti in cui ogni componente è caratterizzato da proprietà ( attributi ) e azioni ( metodi ) sistema è un’ insieme di entità interagenti ( oggetti ) sistema
5.
6. Quindi quello che cambia è solamente del problema... sequenza interazione la visione algoritmo sistema
7.
8. Programmi Algoritmi dati + Per la risoluzione di un Problema metodi attributi Oggetti + Per la gestione di un Sistema
9. Problema complesso scomposizione in procedure scomposizione in entità interagenti (oggetti) Sistema complesso ricapitolando... Programmazione imperativa orientata agli oggetti Programmazione
11. Oggetto = istanza di una Classe automobile velocità colore livello carburante posizione marcia avvia accelera gira fermati cambia marcia rifornisci Classe Ford Focus 1.4 Velocità = 108 colore = nero livello carburante = 15,6 posizione marcia = 5 oggetto Fiat Punto 60 Velocità = 65 colore = verde livello carburante = 32,4 posizione marcia = 3 oggetto
12. Diagramma delle Classi caratteristiche specifiche comportamenti generali nome classe attributo1 attributo2 attributo3 attributo4 metodo1 metodo2 metodo3 metodo4 metodo5 metodo6 automobile velocità colore livello carburante posizione marcia avviati accelera sterza spegniti cambia marcia frena
13. Diagramma degli Oggetti cambiano le caratteristiche specifiche a seconda dell’oggetto istanziato ( i comportamenti non ci sono perché comuni a tutti gli oggetti appartenenti a quella classe ) Ford Focus 1.4 Velocità = 108 colore = nero livello carburante = 15,6 posizione marcia = 5 nome oggetto attributo 1 = val1 attributo 2 = val2 attributo 3 = val3 attributo 4 = val4 Ferrari GA 04 Velocità = 83 colore = rosso livello carburante = 85,1 posizione marcia = 2
14. Classi . Ereditarietà e Gerarchia di ereditarietà . Tipi di ereditarietà . Polimorfismo
15. Ereditarietà classe genitrice costruisco nuove classi partendo da quelle già esistenti automobile a gas velocità colore livello carburante posizione marcia tipo di gas avvia accelera sterza frena cambia marcia accendi luci scambia gas-benz. Nuova Classe automobile velocità colore livello carburante posizione marcia avvia accelera sterza frena cambia marcia accendi luci Classe
16. Gerarchia di ereditarietà Mezzi di trasporto Veicoli a motore Mezzi non a motore Auto a gas Barca Auto Moto Cavallo Bici
17. Gerarchia di ereditarietà Mezzi di trasporto Veicoli a motore Auto a gas Barca Auto Moto Classe Sopraclasse (o Superclasse) Sottoclasse Classe Sopraclasse (o Superclasse) Sottoclasse Classe Sopraclasse (o Superclasse)
18. Tipi di ereditarietà Eredità singola Eredità multipla Mezzi non a motore Cavallo Bici Animali Mezzi non a motore Cavallo
19. Esempio di ereditarietà Mezzi di trasporto velocità numero persone senza patente Veicoli a motore consumo accendi spegni accelera frena Moto cupolino numero ruote piega accelera impenna
20. Ereditarietà Classe Sottoclasse La Sottoclasse si differenzia: per Estensione quando la sottoclasse aggiunge nuovi attributi e metodi 1 . per Ridefinizione quando la sottoclasse ridefinisce i metodi riscrivendone il codice ereditato ( overriding del metodo ) 2 .
21. Polimorfismo . 1° Indica la possibilità per i metodi di assumere forme diverse (cioè implementazioni diverse) all’interno della gerarchia delle classi Veicoli a motore Auto Moto accelera accelera accelera implementazione
22. Polimorfismo . 2° Classe Auto Frena (mano, 3) Frena ( ) Frena (motore) ( overloading dei metodi ) Indica la possibilità per i metodi di assumere forme diverse (cioè implementazioni diverse) all’interno della stessa classe parametri = nome
23. Oggetti . Attributi e Metodi . Incapsulamento . Struttura degli oggetti . Interazione tra oggetti . L’interfaccia verso l’esterno
24. metodi attributi Oggetti + attributo 1 attributo2 attributo3 attributo4 metodo 1 metodo2 metodo3 metodo4 metodo5 metodo6 Costituiscono la memoria dell’oggetto e consentono di tenere traccia dello stato dell’oggetto Sono le operazioni che un oggetto è in grado di compiere ( comportamenti ) Attraverso i metodi un oggetto può accedere alla sua memoria e modificare il suo stato
25. Oggetti attributi Descrivono le proprietà statiche dell’oggetto Nella programmazione gli attributi vengono realizzati attraverso l’uso delle variabili utilizzate dall’oggetto per memorizzare i dati metodi attributi +
26. metodi attributi Oggetti + metodi Descrivono le proprietà dinamiche dell’oggetto Nella programmazione i metodi vengono realizzati attraverso la scrittura di codice ( procedure e funzioni ) che implementano le operazioni dell’oggetto
27. Incapsulamento Viene visto come una scatola nera ( o blackbox ) permettendo così il mascheramento dell’informazione ( information hiding ) La proprietà dell’oggetto di incorporare al suo interno attributi e metodi viene detta incapsulamento metodi attributi metodi attributi Sezione Pubblica Sezione Privata L’oggetto è quindi un contenitore sia di strutture dati e sia di procedure che li utilizzano
28. Sezione Pubblica attributi e metodi che si vogliono rendere visibili all’esterno ( e quindi utilizzabili dagli altri oggetti ) Struttura degli oggetti Sezione Privata attributi e metodi che non sono accessibili ad altri oggetti ( e quindi si rendono invisibili all’esterno ) pubblica privata
29. L’interfaccia verso l’esterno Un oggetto può essere utilizzato inviando ad esso dei messaggi Ambiente esterno L’interfaccia non consente di vedere come sono implementati i metodi, ma ne permette il loro utilizzo e l’accesso agli attributi pubblici L’insieme dei messaggi rappresenta l’interfaccia di quell’oggetto Sezione Pubblica avvia( ) accelera( ) sterza( ) frena( ) liv.carburante velocità Sezione Privata ?
30. Interazione fra gli oggetti Un programma ad oggetti è caratterizzato dalla presenza di tanti oggetti che interagiscono fra loro attraverso il meccanismo dello scambio di messaggi Metodi: accelera( ) sterza( ) frena( ) Messaggi: FerrariGA2004 .accelera( ) FerrariGA2004 .frena( ) Ferrari GA 04 Velocità = 83 colore = rosso liv.carburante = 85,1 posizione marcia = 2 Schumacher Data Nascita = 3/1/69 nazione = germania peso = 74 altezza = 174
31.
32. Es. di scambio di messaggi Metodo : accelera( ) FerrariGA04 . accelera( ) Serbatoio . diminuisci( ) Attributi : velocità = 92 giri motore= 9300 Metodo : diminuisci( ) FerrariGA04 . liv.carburante = 85,1 Attributo : quantità = 85,1 Attributo : liv.carburante = 85,1 Ferrari GA 04 Velocità = 83 colore = rosso liv.carburante = 85,3 posizione marcia = 2 giri motore = 8700 Schumacher Data Nascita = 3/1/69 nazione = germania peso = 74 altezza = 174 Serbatoio quantità = 85,3 tipo benz. = superF1 riserva = 15 peso = 77,3 A B C A B C
33. Nuova Metodologia Per costruire un programma orientato agli oggetti occorre: . Stabilire come gli oggetti interagiscono fra loro . . Definire le classi , indicando gli attributi e i metodi . Identificare gli oggetti che caratterizzano il modello del problema
35. Linguaggi Puri ogni cosa è un oggetto ( ...anche un numero intero è definito come oggetto ) . Smalltalk . Eiffel Linguaggi ibridi alcuni tipi di dati non sono oggetti ( maggiore libertà a scapito di una maggiore chiarezza ) . C++ . Java . Visual Basic . Delphi
36. # include <iostream.h> class Base { friend void funzione {Base&}; public : int pubblico; void Pubblico() {cout <<‘Pubblico: ‘<<pubblico<<end1;}; private : int privato; void Privato() {cout <<‘Pubblico: ‘<<pubblico<<end1;}; protected : int protetto; void Protetto() {cout <<‘Protetto: ‘<<protetto<<end1;}; }; void funzione{Base &istanza} { istanza.pubblico =1; istanza.privato =2; istanza.protetto=3; istanza.Pubblico(); istanza.Privato(); istanza.Protetto(); } void main() { Base istanzabase; istanzabase.pubblico =10; funzione(istanzabase); } C++
37. import java.applet.*; import java.awt.*; public class semplice extends Applet { private TextArea ta; private Label l; public void init() { ta = new TextArea(10,8); l = new Label(“numeri casuali”, Label.CENTER); l.setBackground(Color.Yellow); setLayout(new BorderLayout()); add(l, “center”); add(ta “east”); generaNumeri(); } Public void generaNumeri() { int casuale; for ( int i=1; i<=10; i++) { casuale = (int (Math.random()*1000); ta.append(“-> ”+casuale+””); } } } Java
38. Private Sub Command1_Click() N = Val(InputBox(“Numero di cui vuoi la radice quadrata :”,”Radice Quadrata”)) Msg = “La radice quadrata di “& N SqrN = RadiceQ(N) Select Case SqrN Case 0 Msg = Msg & “è zero.” Case –1 Msg = Msg & “è un numero immaginario.” Case Else Msg = Msg & “è” & SqrN End Select MsgBox Msg End Sub Visual Basic
39. unit somma; Interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class (TForm) Button1 : TButton; Edit1 : TEdit; Edit2 : TEdit; Edit3 : TEdit; Button2 : TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); begin Close; end; procedure TForm1.Button2Click(Sender: TObject); begin Edit3.text := IntToStr(StrToInt(Edit1.text) + StrToInt(Edit2.text)); end; end. Delphi