Info-I211 Midterm

¡Supera tus tareas y exámenes ahora con Quizwiz!

Class constant

A constant in OOP its created throw the following: const Name =" Value"; And to refer to it we just do self :: Name; or call the class name instead. In the other hand procedural programming, its defined as define("Name", "Value");

"has-a" relationship.

"composition" implements the "has-a" usually refers to the properties of objects / classes. A car has a steering wheel . A plane has wings.

"is-a" relationship

"inheritance" implements "is-a" relationship A car is a type of vehicle . A plane is a type of vehicle.

A class named Employee is defined as follows: 1 class Hotel { 2 private $bookings; 3 public function getBooking() { 4 //some code skipped 5 } 6 } Create a new Hotel object.

$hilton = new Hotel();

What cannot be used to refer to an OOP class in PHP?

$this

What is the built in PHP variable that refers toi the current OOP object?

$this

What are the five major components of AJAX?

(1) HTML, (2) CSS, (3) JavaScript/JavaScript DOM, (4) the XMLHttpRequest object, and (5) JSON.

The open method of the XMLHttpRequest object: what the three parameters.

(1) requestMethod: governs whether associated data will be sent using the GET method (i.e., appended to the URL, as a query string), or the POST method (i.e., without using the URL). (2) URL: contains the URL of the page that will be processing the XHR request. (3) requestType: mediates whether the request will be asynchronous (true), or synchronous (false).

What is a class? What is an object? How are they related?

A Class is a template for an object that describes the attributes and methods of an object. A class is a complex data type. An Object is representation of a real world object. An object is an instance of a class. Understand an object in OOP is a self-contained entity, which packs both attributes (data) and behaviors (actions).

When a class extends another class, what does the child class inherits from the parent class?

A subclass may inherit public methods including constructors and data members of the superclass. A subclass usually has more functionality and more specific features than its superclass. Inheritance is used to model the is-a relationship.

An AJAX enabled web page contains three JavaScript statements in the specified order below: Statement A displays "A" on the web page with the document.write method. Statement B sends an asynchronous request to a PHP script and then displays "B" on the web page when the server's response has arrived. The PHP script may take 2 seconds to process the request and then respond. Statement C display "C" on the web page with the document.write method. What is the correct sequence of "A", "B", and "C" appearing on the web page?

A, C, B

how to use an event handler to invoke a function when an event occurs.

Event handlers are used to indicate what actions the browser should take to respond to an event. The handlers make the Web page interactive. Event handlers are named with the event prefix "on". (Ex. onload, onlclick, onsubmit, onkeyup, onmousemove) Syntax: object.event_handler = function() { };

Given two classes called Fruit and Apple as follows: class Fruit { // ...... } class Apple extends Fruit { // ...... } What is a correct statement regarding these two classes is correct?

An Apple object can be treated as a Fruit object since an Apple is a Fruit.

Method/Constructor Overriding

An OOP feature that allows a subclass to override a specific implementation of a method that is already provided by its superclass. The new method must have the exact same name as the parent's method, but can have different code in the body. -PHP allows constructor overriding.

Abstract Methods:

Any method that has just the header (Name and Parameters) but not the body (Implementation) must be declared as an abstract method. abstract public function travel();

An object in OOP models a real-world object. Like a real-world object, an OOP object encapsulates both data and __________ into a self-contained entity.

methods

Use scope resolution operator (::) to access a class/static data or methods.

Can use with the self operator or with the class name To access something within the class you would use: self::getEmployeeCount(); to access something outside of the current class you would put something like this: Employee::getEmployeeCount();

What data type is a class?

Complex data type

What is data hiding in OOP? How is it used to encapsulate objects?

Data hiding is defined as the practice of hiding object data in object-oriented programming design. Through applying data hiding, access to objects is restricted to their attributes and methods. Data hiding is part of encapsulation, which serves to separate an object's interface from its implementation.

A house is to a blueprint as a(n) ________ is to a class in OOP.

object

Class interface

Describes how users interact with the class; generally only contains what the user needs to know includes public methods e.g., instantiating an object can contain abstract methods only

Implementation

Details how the class is implemented includes private methods, as well as private attributes e.g., storing a value within a class

DOM

Document Object Model is DOM for short. Every element in a browser window is an object. The DOM defines the way an object is accessed and is the structure where all the objects are arranged. Any HTML document loaded into a browser window becomes a Document object. The root object of the HTML document and the parent of all other objects in the document.

(T/F) In PHP, a class constructor can not accept any parameter.

False

(T/F) In PHP, an OOP class may have multiple parent classes.

False

(T/F) Like any other methods, a class constructor in PHP returns a null or a value other than null.

False

What does a final method mean in OOP?

It means the method cannot be overridden in subclasses.

What are two forms of software re-usability in OOP?

Inheritance Composition

In an OOP class, public methods form the ________, which describes how users of the class interact with the class; private members form the ________, which specifies the details how the class is implemented.

Interface Implementation

What keyword allows a child class to reference its super class?

parent

How do you declare JavaScript variables?

var imgCount;

What plays a roll in AJAX technology?

JS XML/JSON/Text ]HTML/CSS XMLHttpRequest object

Given a JavaScript string below: var numbers = "{"a":1, "b":2, "c":3, "d":4}"; What is the correct JavaScript code that converts numbers to a JSON object with a built-in function?

JSON.parse(numbers)

What are the basic JavaScript syntax rules?

Nearly everything in JavaScript is case sensitive, which means that lowercase and uppercase letters can not be used interchangeably. For example, built-in objects (such as Math or Date) are capitalized while keywords (like if and for) are lowercase. Statements must be ended with a semicolon if multiple statements are on the same line, but are optional if the statement is followed by a line break. This comes into play in scenarios like the following: var i = 0; i++ // <-- semicolon obligatory // (but optional before newline) var i = 0 // <-- semicolon optional i++ // <-- semicolon optional Blank spaces (or whitespace) is ignored by JavaScript, similar to HTML. This is useful in that whitespace can instead be used to separate distinct statements and make the code more readable. When defining a variable, function, or object, the user is able to choose their own name with some exceptions. Terms that make up the JavaScript language such as if or for are "reserved words" and therefore cannot be used.

Use the new command to create/instantiate a new object from a class. Understand a constructor is called when a new class instance is created.

New is used whenever creating a new instance on an object, so you would use new Rectangle to create another rectangle object that gets some of it's information from the Rectangle class. So it would be $r1 = new Rectangle (). Inside the parenthesis could be the parameters you have set up for the rectangle like width or height.

name five common DOM events and their event handlers? Do you understand when these events get triggered?

OnClick - This will get triggered when the user clicks on the object that calls the event handler. OnMouseOver - This will get triggered when the user mouses over the object that calls the event handler. OnLoad - This will get called on the initial load up of the object that calls the event handler. OnKeyUp - This will get called when the user presses the up arrow key on their keyboard. OnMouseOut - This will get called when a user mouse exits an object that would call this specific event.

Encode JSON from arrays in PHP

json_encode method

JSON object values: what types of data can be used?

Strings (can be single- or double-quoted) Numbers (including integers, as well as floats) Booleans (i.e., TRUE or FALSE) Arrays Entire JSON objects Null value

Parse JSON objects in JavaScript:

Syntax - JSON.Parse(text [, reviver]) Text parameter - This is the string that will parse as JSON. Example in javascript from movie catalog example - catalogObj = JSON.parse(loadJSON('movies.json')); This will get the JSON Object defined in an external JSON file. Reviver parameter - This is an optional parameter, but when used it will transform the values before being returned.

How do you use the class member operator (single arrow operator à) to access instance variables or methods of an object?

Syntax: class Person { private $name; public function getName() { return $this->name; } public function setName($name) { $this->name = $name; }

What is the dot (.) operator?

The dot(.) operator in JavaScript is the class member operator. You use this as opposed to -> in PHP. Ex. var today= new Date(); var year = today.getFullYear();

What are the basic JSON syntax rules?

The following demonstrates the JSON syntax: {"name":value} Whenever more than one value is being sent using JSON, the syntax is the same as is shown above, except that commas separate value 1 from value 2, and so on. {"name1":value1, "name2":value2, "name3":value3} The "name" parameter must always be a single-quoted string. Meanwhile, the "value" parameter may contain a single-quoted string, a double-quoted string, an array, an entire JSON object, an integer, a float, a boolean, or a null value.

The send method of the XMLHttpRequest object

The general syntax for send is: send(data); When 'GET' method is used, data parameter is always null (so 'send()' would be used). Data is instead sent via a querystring. When 'POST' method is used, data can be send as parameters (so 'send(data)' would be used). For example: xmlHttp.send(null)

How and when do you use the responseXML or responseText property to retrieve server's responses?

The responseXML or responseText properties are used when the readyState property value is = 4 which means the server's response has arrived successfully and the HTTP status is = 200 which means the request was successful. The responseXML property of the XHR object is used to get the XML response from the server. The responseText property of the XHR object is used to get the text response from the server.

how to access the code defined in a parent class from within a child class.

The way this is done is when you are defining the new class you would add the following phrase: Example: class student extends person

JSON object names: can they be single or double-quoted strings?

While strings contained in the value parameter of JSON objects may be either single- or double-quoted, the names of JSON objects must be double-quoted strings.

Protected

members may be accessed within the class which defines them, any child class.

Given the Javascript variable message that contains a reference to a division block (created with <div>....</div> which of the following JavaScript code assigns a value to a div block?

message.innerHTML ="new content"

PHP only supports single-inheritance

To inherit features from more than one parent, a class may extend one class and implement an interface.

(T/F) In PHP, an OOP class can override the constructor of its parent class.

True

(T/F) In PHP, an OOP class may have multiple child classes.

True

(T/F) In PHP, public and protected features (attributes and methods) defined in a superclass are inherited by its subclasses.

True

(T/F) In PHP, the __autoload function is automatically called when a new object is instantiated.

True

UML

Unified Modeling Language: Used to represent classes and their relationships in OOP Set up: Three components; Class Name, Class Attributes, Class Methods Visibility; -:Private +:Public Return Data types of Methods

What are the new command

Use the new operator to create an object from a class. Ex. $person1 = new Person(); $person1->setName("Judy");

innerHTML v.s. value

Value property is used when a user wants to check what has been inputted in a form field. It's getting specific values out of an HTML element. Whereas innerHTML is for selecting the HTML element as a whole.

What is method overriding in OOP?

When a parent class and a child class both contain a method with the same name, the method implementation in the two method don't have to be the same.

Retrieve data from JSON objects in JavaScript: dot syntax vs square bracket syntax.

When you use the "dot" syntax it looks something like obj.name for example. You use the object and then the dot to access it's property. The [] syntax allows you to access property names with spaces. For example obj["first name"]

self:

a special keyword that refers to the current class. syntax, self::$employee_count

parent:

a special keyword that refers to the super class of the current class. Example: parent::__construct();

$this

a special variable used when referring to the current object. It can be used to pull specific information from objects that differ in comparison.

Polymorphism is one of the three major OOP principles. It means that _____________.

an object of class A can act as an object of class B.

Instance Class Data and Methods:

are attributes and actions specific to a particular instance or object created by from a class

Making a class or method final

are made final if you dont want methods/classes over-written by child classes by ANY MEANS. To make a class / method final, simply use the keyword final .

Static class data and methods

are unique in the sense that they are able to be called without creating an instance and carry the same information so you do not need to create multiple variables or methods. They are defined/created by adding the keyword static before the class data or method. Example: public static function aStaticMethod() { }

Public

can be seen and accessed by everywhere without any restrictions.

Abstract class

can contain either abstract or concrete methods abstract class Animal{ abstract public function Animal() { cannot be instantiated because it is "incomplete" Can be extended and must be extended subclasses must provide implementation of the abstract methods or declare themselves to be abstract

Private

can only be accessed within the class that defines them.

The template or blueprint that defines abstract characteristics of all real world objects of the same kind is called a(n) _____ in OOP.

class

A car is composed of engine, steering wheel, and brakes. The software that models those real-world objects contains classes called Car, Engine, SteeringWheel, and Brakes. What is the type of relationship between Car and Engine?

composition

What is the correct code for defining a class member attribute that is NOT associated with individual instances?

const pi = 3.14; private static $users;

Given a JSON object below that stores a person's name and home phone number: {"Name":"Anna Smith", "Home phone":"555-666-2222"} The JavaScript variable that stores the object is called contact. what is the code that returns the person's name?

contact.name

Given a JSON object below that stores a person's name and home phone number: {"Name":"Anna Smith", "Home phone":"555-666-2222"} The JavaScript variable that stores the object is called contact. What is the code that returns the person's home phone number?

contact["Home phone"]

The readyState property of the XMLHttpRequest object

contains five possible values: 0 means that the object has been created, but that the open method has not been initialized. 1 means that the open method has been called, but that the send method has not been called. 2 means that the send method has been called, but that data is not available. 3 means that some data has been received; however, responseText/responseBody are not available. 4 means that the request has been successfully completed, and thus, response data has been received.

Encapsulation

is the process of including in an object everything that constitutes its attributes and behaviors. It serves to separate the contractual interface of an object and its implementation. Data hiding is part of encapsulation.

How do you use the onreadystatechange event handler to specify a named or anonymous function to handle server responses?

is triggered when the ready state property of the XHR object changes. When onreadystatechange detects a status change in the XHR object it calls a function to handle the server's response.

XMLHttpRequest object

is used to exchange data with a server behind the scenes. This means that it is possible to update parts of a web page. This happens without reloading the whole page. Reply

Object-oriented programming promotes a way of programming that allows programmers to think in term of _______.

data

Asynchronous Requests

deal with file, server and browser communication, particularly in Javascript. Can run without the page re-loading, as they run in the background separate from the browser.

Synchronous requests

deal with file, server and browser communication, particularly in Javascript. Only load when the browser page is refreshed.

Given HTML code below: <div id="message">....</div> Which of the following JavaScript code returns the reference to the divison block

document.getElementById('message')

What is the class scope resolution operator in PHP?

double colon (::)

Static Class Data and Methods

e attributes or actions you want each instance or object to have in common. For instance you want the value of pi to be the same for every shape (static/class), but you probably want the overall area to vary between each shape object (instance). public static function getCircleCount(){ .... }

Inheritance

enables new objects to take on the properties of existing objects. A class that us used as the basis for inheritance is called a superclass.

In OOP, attributes (data) and behaviors (methods) of an object are packaged into a single entity. An object hides its data by making them private and exposes them through public methods. The above practice explains one of the three major principles of OOP, which is called _________.

encapsulation

Given an OOP class: ____ class A { //code omitted } What modifier should be used in the blank in class A to prevent class A from being extended?

final

how do you create a function in JavaScript.

function hello()

Sending an AJAX request with the ______ method allows data to be sent using querystring variables.

get

how to use the getElementById method to get the reference to any element on a web page.

getElementById Examples: document.getElementById('firstname'); document.getElementById('message');

multiple inheritance

in languages such as Java and Python, where object can inherent behaviors and attributes from multiple parent classes.

Default constructor

is a constructor that doesn't accept parameters. It is automatically created for any object that doesn't have any parameterized constructors. It is not automatically created when there are other constructors in the object.

Visibility modifiers public and ______ make a class data member to be accessible to the class that defines the data member and all of its child classes.

protected

Create a default constructor

public function __construct() {}

Single Inheritance

refers to an object only being able to have 1 parent class to inherent from. This is crucial for when you are designing classes .

Polymorphism

refers to programming languages ability to process objects differently depending on their data type or class. It is the ability to redefine methods for derived classes. The word literally means "many shapes." It is the ability of one object to take on many forms. It can be accomplished using inheritance or interfaces.

In an OOP object, a get method (getter) enables a client (the user of the object) to ________.

retrieve the value of the objects property

Which of the following is the correct symbol/operator to access a class member with an object?

single arrow (->)

Constructor

special method used to initialize object attributes. Constructors are called whenever a new instance is created. It never returns a vale. Named _construct

Sometimes, it is useful if we can access methods and properties in the context of a class rather than an object. To do this, you can use ______ keyword.

static

Given a XMLHttpRequest object named xhr and a function named hdndleServerResponse, which of the following is the correct code that specifies the function to call when the state of the XMLHttpRequest object changes?

xhr.onreadystatechange=handleServerResponse


Conjuntos de estudio relacionados

Chapter 12 LearnSmart: Nervous System (Nervous Tissue)

View Set

Columbian Exchange: Negative Effects From The Worlds Old to New

View Set

Chapter 15: DNA and Gene Synthesis and Repair

View Set

Medical Assistant Health Insurance Terms

View Set