OOP-Pillars, Etc.

Ace your homework & exams now with Quizwiz!

How do you instantiate an instance of a class in Java?

1- premadeClass obj=new premadeClass(); "obj" is now an instance or object of premadeClass int

Type an Object Declaration!

1- Snake fluffy = new Snake("Fluffy","rainbow boa", 10, "albino"); -(Snake fluffy)=declaration 2- Rectangle rectOne = new Rectangle(originOne, 100, 200); -(Rectangle rectOne)=variable declaration that associate a variable name with an object type

Provide an example of Inheritance!

1- the keyword used for inheritance is extends example: //parent class class Motorcycle{ public int speed; public int gear; -//Constructor public Motorcycle(int gear, int speed){ this.gear=gear; this.speed=speed; } } //subclass extending base-class class MountainBike extends Motorcycle{ //unique constructor public MountainBike(int gear, int speed, int startHeight){ //super is the inheritance!! super(gear,speed);seatHeight=startHeight; } }

Abstraction

1-Abstraction is a process of exposing essential features of the application and hiding the details. 2-Absrtract Methods can be used in C# to implement methods without exposing their "implementation" an abstract method may have dog.woof(); and its subclass may have Pomeranian.woof() + .dig(), but if you Upcast to dog, the user only has access to .woof(); and never really knows that .dig ever existed. this clears up code and readability 3-Abstraction reduces code complexity and at the same time makes code aesthetically pleasant

What is the Difference between an object and a class?

1-Classes can be thought of as a 'type', with the objects being a 'variable' of that type example: poodle=new Dog(); poodle=OBJECT; Dog()=CLASS; 2-A class is a template for objects. a Blueprint 3-A class defines object properties including a valid range of values, and a default value 4-A class also describes object behavior 5-Most importantly, an object is a member or an INSTANCE of a class 6-An object has a state in which all of its properties have values that you either explicitly define or that are defined by default settings

What is an Object?

1-State: it is represented by attributes of an object; also reflects the properties of an object 2-Behavior: represented by methods of an object;also reflects the response of an object with other objects 3-Identity:gives a unique name to an object and enables one object to interact with other objects example- DOG identity=name of dog; State/Attributes=breed,age; behaviors=Bark,SLeep,Eat 4-objects correspond to things found in the real world; they are the instances of the class that are interacted with by through use of the program

What is a Class?

1-a class is a user-defined blueprint from which objects are creates 2-represents the set of properties or methods that are common to all objects of one type 3-Modifiers: a class can be public or has default access 4-Class name:name should begin with a initial letter (capitalized by convention) 5-Superclass(if any):name of the class's parent, preceded by the keyword 'extends'; a class can only extent(subclass) one parent 6-Interfaces:a comma-separated list of interfaces implemented by the class preceded by keyword 'implements';class can implement more than one interface 7-class body surrounded by curly braces

Inheritance

1-in OOP, the base class(the existing class/sometimes called the parent class) has properties and methods that will be inherited by the subclass(sometimes called the subtype or child class) and that subclass can have additional properties or methods. 2-The ability to create a new class from an existing class 3-A way to reuse code without messing with the base class, just the one subclass you may be using

Polymorphism

1-refers to the ability to take into different forms or stages 2-A subclass can define its own unique behavior and still share same functionalities or behavior of its parent/base class 3-this works one-way, base class cannot inherit and thus use functionalities from subclass 4-polymorphism is the ability of an object to change behavior on runtime 5- The ability for multiple objects of the same base class, but different subclasses to override a method of the base class and perform different operations on that same method.

Additional OOP Info:

ABSTRACTION- 1-Separation between needed functionality and implementation details 2-leaks implementation details that are impossible to stop, but tries to stop the rest ENCAPSULATION- 1-Bundle data and behavior into objects 2-hide implementation-specific dat/behavior INHERITANCE- 1-Abilitt to derive a class from another class, gaining its data and behavior 2-C# does not allow extending more than one class POLYMORHPISM 1-Ability to treat a derived-class object as though it were a base-class object (upcasting?) 2-Method Overloading(same method name, different parameters) adhoc polymorphism 3-generic types(?)

Encapsulation

Encapsulation is implemented by using access specifiers: public private internal protected protected internal partial Getters and setters are also good examples of encapsulation:Data Binding 1-Hides your modules' internal data and all other implementation details/mechanisms from other modules 2-A way of restricting access to certain properties or components 3-can also be called 'data binding'; encapsulation is all about binding the data variables and functions together in a class 4-so Encapsulation means binding the data members and methods together in a capsule form to avoid accidental changes to data from external users. Bundling of algorithms and data 5-Abstraction differs bcuz it only gives essential things to the users and 'omits' unnecessary details. Specific to END USER and their permissions. Encapsulation is more for security, whereas abstraction is about giving user important methods without Explicitly showing details in order to increase readability of code

Difference between Abstraction and Interface?

INTERFACES 1-An interface is a contract:the person writing the interface says, "hey I accept things looking that way only. and the person using the interface says "ok, the calss I write looks that way" 2-An interface is an empty shell. There are only the signatures of methods. which implies that the methods do not have a body. THE INTERFACE CANNOT DO ANYTHING. IT IS JUST A PATTERN; like an empty class with rules one MUST follow? ABSTRACTION 1-Abstract classes, unlike interfaces, are classes. They are most expressive to use because there is a lot of look-up to do when you inherit them 2-Abstract classes look a lot like interfaces, but they have something more: You can define a BEHAVIOR for them DIFFERENCES- -Abstract classes can have constants, members, method stubs (methods without a body) and defined methods, whereas interfaces can only have constants and methods stubs. -Methods and members of an abstract class can be defined with any visibility, whereas all methods of an interface must be defined as public (they are defined public by default). -An interface contains only incomplete members(signature of member;AN abstract class contains both incomplete (abstract) and complete member -Members of interface can not be Static; Only Complete Member of abstract can be Static

OOP-definition

Object-oriented programming is a programming paradigm using 'objects'-usually instances of a class-consisting of data fields and methods together with their interactions-to design applications and computer programs


Related study sets

Chapter Thirteen Questions + Answers

View Set

The Legal Environment of Business - Midterm

View Set

Unit 1: Operations with Real Numbers

View Set

World History 112 Final Study Guid

View Set

HIPAA AND PRIVACY ACT TRAINING (CHALLENGE EXAM JKO)

View Set

A Level Chemistry - Organic Chemistry - Topic 2 - Alkanes

View Set

Closed chest - Chest tubes. Lewis pgs 519-524

View Set

Test - Module 13 - Civilizations of the Americas

View Set