Chapter 2 - OOP Maciej Mensfeld Presented by: Maciej Mensfeld More about OOP dev.mensfeld.pl github.com/mensfeld.

Slides:



Advertisements
Similar presentations
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Advertisements

Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
Pemrograman VisualMinggu …3… Page 1 MINGGU Ke Tiga Pemrograman Visual Pokok Bahasan: Class, Objects, Methods and Instance Variable Tujuan Instruksional.
Written by: Dr. JJ Shepherd
Chapter User authorization & safety Maciej Mensfeld Presented by: Maciej Mensfeld User authorization & safety dev.mensfeld.pl.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
1 Chapter 12 Working With Access 2000 on the Internet.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Object-Oriented Application Development Using VB.NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 10 Classes Continued
Ruby (on Rails) Slides modified by ements-2ed.shtml) 1.
Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction dev.mensfeld.pl github.com/mensfeld.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
UML Basics & Access Modifier
ACM Web Development Workshop - PHP By Luis Torres.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Chapter 12: Adding Functionality to Your Classes.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Chapter 4.1 – Deeper into Rails Maciej Mensfeld Presented by: Maciej Mensfeld Deeper into Rails mensfeld.pl github.com/mensfeld senior.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Classes and Objects. Topics The Class Definition Declaring Instance Member Variables Writing Instance Member Methods Creating Objects Sending Messages.
Unit 2, cont. September 12 More HTML. Attributes Some tags are modifiable with attributes This changes the way a tag behaves Modifying a tag requires.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Object-Oriented PHP (Chapter 6).
OOP IN PHP `Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For.
C#/Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
Object-Oriented Programming Chapter Chapter
Web applications – what & why? Maciej Mensfeld Presented by: Maciej Mensfeld Web applications – what & why? dev.mensfeld.pl github.com/mensfeld.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
C# Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the properties.
CITA 342 Section 1 Object Oriented Programming (OOP)
SSE693 C# and.NET Dr. MacNeil Summer 2005 Jay Clary / Lance Hilliard Team Project 3.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Written by: Dr. JJ Shepherd
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
1 Introduction to Object Oriented Programming Chapter 10.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Class Fundamentals BCIS 3680 Enterprise Programming.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Ruby Metaprogramming and other languages….
One class is an extension of another.
Chapter 9 Objects and Classes
CSE 1030: Implementing GUI Mark Shtern.
Fundaments of Game Design
Object Oriented Programming
CSG2H3 Object Oriented Programming
Presentation transcript:

Chapter 2 - OOP Maciej Mensfeld Presented by: Maciej Mensfeld More about OOP dev.mensfeld.pl github.com/mensfeld

Chapter 2 - OOP Maciej Mensfeld Classes

Chapter 2 - OOP Maciej Mensfeld Variables in a Ruby Class Ruby provides four types of variables: Local Variables: Local variables are the variables that are defined in a method. Local variables are not available outside the method. Instance Variables: Instance variables are available across methods for any particular instance or object. That means that instance variables change from object to object. Instance variables are preceded by the at sign followed by the variable name.

Chapter 2 - OOP Maciej Mensfeld Variables in a Ruby Class Ruby provides four types of variables: Class Variables: Class variables are available across different objects. A class variable belongs to the class and is a characteristic of a class. They are preceded by the sign and are followed by the variable name. Global Variables: Class variables are not available across classes. If you want to have a single variable, which is available across classes, you need to define a global variable. The global variables are always preceded by the dollar sign ($).

Chapter 2 - OOP Maciej Mensfeld Custom Method to create Objects When you plan to declare the new method with parameters, you need to declare the method initialize at the time of the class creation. The initialize method is a special type of method, which will be executed when the new method of the class is called with parameters.

Chapter 2 - The accessors & setters Maciej Mensfeld The accessor & setter methods Accessors

Chapter 2 - The accessors & setters Maciej Mensfeld The accessor & setter methods Setters

Chapter 2 - The accessors & setters Maciej Mensfeld The accessor & setter methods Setters + getters

Chapter 2 - Access Control Maciej Mensfeld Access Control

Chapter 2 - Access Control Maciej Mensfeld Access Control Public Methods: Public methods can be called by anyone. Methods are public by default except for initialize, which is always private. Private Methods: Private methods cannot be accessed, or even viewed from outside the class. Only the class methods can access private members. Protected Methods: A protected method can be invoked only by objects of the defining class and its subclasses. Access is kept within the family.

Chapter 2 - Inheritance Maciej Mensfeld Class Inheritance This is how it works

Chapter 2 - Inheritance Maciej Mensfeld Class Inheritance Ruby does not support Multiple level of inheritances but Ruby supports mixins. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.

Chapter 2 – let’s do programming! Maciej Mensfeld A bit of programming

Chapter 2 – writing some cool stuff Maciej Mensfeld Web crawler! Enough theory! Let’s be pragmatic! Simple web crawler requirements Fetch and store urls Don’t revisit urls Search 4 keywords (support regexp) Print results

Chapter 2 – writing some cool stuff Maciej Mensfeld Web crawler – page content parser What do we need? ParserCrawler Extracts data from page content Crawl all available pages

Chapter 2 – writing some cool stuff Maciej Mensfeld Simple parser – 13LOC attr_reader – set instance variable as readonly from the outside attr_accessor – make instanca variable R/W from the outside

Chapter 2 – writing some cool stuff Maciej Mensfeld Simple parser – 13LOC Try it out!

Chapter 2 – writing some cool stuff Maciej Mensfeld Crawler – How should it work? Try to download page Success? Select another page No Yes Do something with result (parse, send, etc) Mark page as visited

Chapter 2 – writing some cool stuff Maciej Mensfeld Crawler – 37LOC Try it out! Add our start url to array (basicly array with one address in it) No pages where visited yet – = [] (empty array) We will check only pages with specified extensions (html, asp, php, etc)

Chapter 2 – writing some cool stuff Maciej Mensfeld20/23 Crawler – read page in Ruby Try it out! Mark page as visited (add it array) Load current content page (parse URL and address) Catch any type of exception (404, 500, etc) – mark page as visited so we don’t go there again and return false Reading pages in Ruby is easy!

Chapter 2 – writing some cool stuff Maciej Mensfeld Crawler – extract URLs Try it out! Use URI.extract method to extract all urls Check if URL is valid (try to parse it and check extension) If anything failes – assume that this URL is incorrect Reading pages in Ruby is easy!

Chapter 2 – writing some cool stuff Maciej Mensfeld Crawler – run crawler! Try it out!

Chapter 2 - OOP Maciej Mensfeld THX Presented by: Maciej Mensfeld dev.mensfeld.pl github.com/mensfeld