SlideShare a Scribd company logo
1 of 5
Download to read offline
1 ថនសារិ
Review OOP and OOD
I. QCM
 CLASS
 Class is a blueprint for an object. In fact, classes describe the type of objects, while objects are usable instances
of classes.
 We use Class because:
 They provide useful abstraction and structure
 They help you think about the application you are building
 Class name are nouns, not verbs
 Good: Expense Claim, Employee, Printer
 Bad: Ordering, Personnel, System
 Don’t Overdo inheritance………
 How We use Class:
A class is a user defined blueprint or prototype from which objects are created. It represents the set of
properties or methods that are common to all objects of one type. In general, class declarations can
include these components, in order:
Modifiers : A class can be public or has default access (Refer this for details).
Class name: The name should begin with a initial letter (capitalized by convention).
Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword
extends. A class can only extend (subclass) one parent.
Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded
by the keyword implements. A class can implement more than one interface.
Body: The class body surrounded by braces, { }.
Constructors are used for initializing new objects. Fields are variables that provides the state of the class
and its objects, and methods are used to implement the behavior of the class and its objects.
There are various types of classes that are used in real time applications such as nested
classes, anonymous classes, lambda expressions.
 Abstract Class
 Abstract Class are classes that contain one or more abstract methods.
 We use Abstract Class Because:
An abstract class is a special kind of class that cannot be instantiated. So the question is why we need
a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other
words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it
enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all
the subclasses to carry on the same hierarchies or standards.
 How we use Class:
An abstract class is a class that is declared abstract—it may or may not include abstract
methods. Abstract classes cannot be instantiated, but they can be subclassed.
An abstract method is a method that is declared without an implementation (without braces, and
followed by a semicolon), like this:
abstract void moveTo(double deltaX, double deltaY);
If a class includes abstract methods, then the class itself must be declared abstract, as in:
public abstract class GraphicObject {
// declare fields
// declare nonabstract methods
abstract void draw();
}
2 ថនសារិ
When an abstract class is subclassed, the subclass usually provides implementations for all of the
abstract methods in its parent class. However, if it does not, then the subclass must also be
declared abstract.
 Inheritance
 inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the
definitions of one or more general classes.
 We use inheritance because:
Inheritance is a term for reusing code by a mechanism of passing down information and behavior from a
parent class to a child or sub class. It’s pretty easy to understand really. Just like a child can inherit various
mannerisms and behaviors from his or her biological parents, in software this same concept holds true. By
leveraging the power of inheritance and creating child classes that extend their parent, we can make sub
classes with super powers that have everything their parent has and more. Let’s take a look at how
inheritance works in PHP.
II. Question
 Singleton Vs Factory Method
 Singleton
 A singleton pattern ensures that you always get back the same instance of
whatever type you are retrieving, whereas the factory pattern generally gives you a
different instance of each type.
 The purpose of the singleton is where you want all calls to go through the same
instance. An example of this might be a class that manages a disk cache, or gets
data from a static dictionary; wherever it is important only one known instance
interacts with the resource. This does make it less scalable.
 Factory Method:
 Object creation without exposing in to client
 Refer to newly created objects through interface
 Define the interface for creating an object
 The purpose of the factory is to create and return new instances. Often, these won’t
actually be the same type at all, but they will be implementations of the same base
class. However, there may be many instances of each type
 Creational Vs Structural
 Creational
These design patterns provide ways to create objects while hiding the creation logic, instead of
instantiating objects directly using the newoperator. This gives the program more flexibility in deciding
which objects need to be created for a given use case.
 Structural
 These design patterns deal with class and object composition. The concept of inheritance is used to
compose interfaces and define ways to compose objects to obtain new functionality.
 Structural Vs Behavioral
 Structural
Structural modelling refers to that type of modelling in which we simply interconnect the components by
mapping there ports by seeing the rtl diagram whereas
 Behavioral
Behavioral modelling uses sequential statement inside the process statement ,in it we implement the logic
directly and this modelling is preferred and is the highest level of abstraction
3 ថនសារិ
 Strategy vs Command
 Strategy
Strategy, in contrasst, is used to customize an algorithm. A strategy might have a number of methods
specific to the algorithm. Most often strategies will be instanciated immediately before executing the
algorithm, and discarded afterwards.
 Command
Command encapsulates a single action. It therefore tends to have a single method with a rather generic
signature. It often is intended to be stored for a longer time and to be executed later - or it is used to
provide undo functionality (in which case it will have at least two methods, of course).
 What is the benefit of
 Singleton
 Ensures only one instance of class is ever created
 Can get access to data in this class from anywhere
 Acts like global variables
 Can cause methods to have unintended side-effects due to data sharing via state in the Singleton
 Factory
 Allows the sub-classes to choose the type of objects to create
 Promoted the loose –coupling by eliminating the need to bind application-specific classes into the code
.That mean the code interacts solely with the resultant interface or abstract class,so that it will work
with any classes that implement that interface or that extends that abstract class.
 Usage:
1. When a class doesn’t know what the sub-classes will be required to create
2. When a class want that it’s sub-classes specify the object to be created
3. When the parent class choose the creation of objects to its sub-classes
 Strategy
 Forces organizations to look ahead
 Improved fit with the environment
 Better use of resources
 Provides a direction/vision
 Helps monitor progress
 Ensures goal congruence
 Command
 It decouples the classes that invoke the operation from the object that knows how to execute the
operation
 It allow you to create a sequence of command by providing a queue system
 Extensions to add a new command is easy and can be done without changing the existing code
 You can also define a rollback system with the command pattern.
4 ថនសារិ
III. Coding
 Factory Method
 Strategy
5 ថនសារិ
 Command

More Related Content

What's hot

Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Sakthi Durai
 
What are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaWhat are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaEdureka!
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaMOHIT AGARWAL
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classesAnup Burange
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation javaJayasankarPR2
 
Chapter 5 declaring classes & oop
Chapter 5 declaring classes  & oopChapter 5 declaring classes  & oop
Chapter 5 declaring classes & oopsshhzap
 
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceJava OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceOUM SAOKOSAL
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2sotlsoc
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Nuzhat Memon
 
Class properties
Class propertiesClass properties
Class propertiesSiva Priya
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 

What's hot (20)

Abstract method
Abstract methodAbstract method
Abstract method
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
What are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaWhat are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | Edureka
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Hemajava
HemajavaHemajava
Hemajava
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation java
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Chapter 5 declaring classes & oop
Chapter 5 declaring classes  & oopChapter 5 declaring classes  & oop
Chapter 5 declaring classes & oop
 
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceJava OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & Interface
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2
 
Interfaces & Packages V2
Interfaces & Packages V2Interfaces & Packages V2
Interfaces & Packages V2
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
 
Class properties
Class propertiesClass properties
Class properties
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 

Similar to Review oop and ood (20)

Oops
OopsOops
Oops
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
C#
C#C#
C#
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java basics
Java basicsJava basics
Java basics
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
C# program structure
C# program structureC# program structure
C# program structure
 
01. design pattern
01. design pattern01. design pattern
01. design pattern
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Java mcq
Java mcqJava mcq
Java mcq
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 

More from than sare

Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4than sare
 
Project Management_Review_2018
Project Management_Review_2018Project Management_Review_2018
Project Management_Review_2018than sare
 
Android review_for final Semester II of Year4
Android review_for final Semester II of Year4Android review_for final Semester II of Year4
Android review_for final Semester II of Year4than sare
 
Importain questions e_commerce_preview questions
Importain questions e_commerce_preview questionsImportain questions e_commerce_preview questions
Importain questions e_commerce_preview questionsthan sare
 
E commerce preview questions23 jul-2018
E commerce preview questions23 jul-2018E commerce preview questions23 jul-2018
E commerce preview questions23 jul-2018than sare
 
Physic grade-12
Physic grade-12Physic grade-12
Physic grade-12than sare
 
Business plan
Business planBusiness plan
Business planthan sare
 
Share point review qustions
Share point review qustionsShare point review qustions
Share point review qustionsthan sare
 
Share point answer the question
Share point answer the questionShare point answer the question
Share point answer the questionthan sare
 
Judging rubric
Judging rubricJudging rubric
Judging rubricthan sare
 
Smartphone v ideo editing manual-ios(Tech By Ms.THAN Sare)
Smartphone v ideo  editing manual-ios(Tech By Ms.THAN Sare)Smartphone v ideo  editing manual-ios(Tech By Ms.THAN Sare)
Smartphone v ideo editing manual-ios(Tech By Ms.THAN Sare)than sare
 
Database(db sql) review
Database(db sql) reviewDatabase(db sql) review
Database(db sql) reviewthan sare
 
Mid term & final- preparation- student-review(Oracle)
Mid term & final- preparation- student-review(Oracle)Mid term & final- preparation- student-review(Oracle)
Mid term & final- preparation- student-review(Oracle)than sare
 
Answer ado.net pre-exam2018
Answer ado.net pre-exam2018Answer ado.net pre-exam2018
Answer ado.net pre-exam2018than sare
 
Technovation week6 planning_yourcode
Technovation week6 planning_yourcodeTechnovation week6 planning_yourcode
Technovation week6 planning_yourcodethan sare
 
Sen sors(technovation) week6_thansare
Sen sors(technovation) week6_thansareSen sors(technovation) week6_thansare
Sen sors(technovation) week6_thansarethan sare
 
Week5(technovation)-Teach by Mr.than Sare
Week5(technovation)-Teach by Mr.than SareWeek5(technovation)-Teach by Mr.than Sare
Week5(technovation)-Teach by Mr.than Sarethan sare
 
App inventor week4(technovation)
App inventor week4(technovation)App inventor week4(technovation)
App inventor week4(technovation)than sare
 
Algorithm week2(technovation)
Algorithm week2(technovation)Algorithm week2(technovation)
Algorithm week2(technovation)than sare
 

More from than sare (20)

Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
 
Project Management_Review_2018
Project Management_Review_2018Project Management_Review_2018
Project Management_Review_2018
 
Android review_for final Semester II of Year4
Android review_for final Semester II of Year4Android review_for final Semester II of Year4
Android review_for final Semester II of Year4
 
Importain questions e_commerce_preview questions
Importain questions e_commerce_preview questionsImportain questions e_commerce_preview questions
Importain questions e_commerce_preview questions
 
E commerce preview questions23 jul-2018
E commerce preview questions23 jul-2018E commerce preview questions23 jul-2018
E commerce preview questions23 jul-2018
 
Physic 12-2
Physic 12-2Physic 12-2
Physic 12-2
 
Physic grade-12
Physic grade-12Physic grade-12
Physic grade-12
 
Business plan
Business planBusiness plan
Business plan
 
Share point review qustions
Share point review qustionsShare point review qustions
Share point review qustions
 
Share point answer the question
Share point answer the questionShare point answer the question
Share point answer the question
 
Judging rubric
Judging rubricJudging rubric
Judging rubric
 
Smartphone v ideo editing manual-ios(Tech By Ms.THAN Sare)
Smartphone v ideo  editing manual-ios(Tech By Ms.THAN Sare)Smartphone v ideo  editing manual-ios(Tech By Ms.THAN Sare)
Smartphone v ideo editing manual-ios(Tech By Ms.THAN Sare)
 
Database(db sql) review
Database(db sql) reviewDatabase(db sql) review
Database(db sql) review
 
Mid term & final- preparation- student-review(Oracle)
Mid term & final- preparation- student-review(Oracle)Mid term & final- preparation- student-review(Oracle)
Mid term & final- preparation- student-review(Oracle)
 
Answer ado.net pre-exam2018
Answer ado.net pre-exam2018Answer ado.net pre-exam2018
Answer ado.net pre-exam2018
 
Technovation week6 planning_yourcode
Technovation week6 planning_yourcodeTechnovation week6 planning_yourcode
Technovation week6 planning_yourcode
 
Sen sors(technovation) week6_thansare
Sen sors(technovation) week6_thansareSen sors(technovation) week6_thansare
Sen sors(technovation) week6_thansare
 
Week5(technovation)-Teach by Mr.than Sare
Week5(technovation)-Teach by Mr.than SareWeek5(technovation)-Teach by Mr.than Sare
Week5(technovation)-Teach by Mr.than Sare
 
App inventor week4(technovation)
App inventor week4(technovation)App inventor week4(technovation)
App inventor week4(technovation)
 
Algorithm week2(technovation)
Algorithm week2(technovation)Algorithm week2(technovation)
Algorithm week2(technovation)
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Review oop and ood

  • 1. 1 ថនសារិ Review OOP and OOD I. QCM  CLASS  Class is a blueprint for an object. In fact, classes describe the type of objects, while objects are usable instances of classes.  We use Class because:  They provide useful abstraction and structure  They help you think about the application you are building  Class name are nouns, not verbs  Good: Expense Claim, Employee, Printer  Bad: Ordering, Personnel, System  Don’t Overdo inheritance………  How We use Class: A class is a user defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type. In general, class declarations can include these components, in order: Modifiers : A class can be public or has default access (Refer this for details). Class name: The name should begin with a initial letter (capitalized by convention). Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent. Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface. Body: The class body surrounded by braces, { }. Constructors are used for initializing new objects. Fields are variables that provides the state of the class and its objects, and methods are used to implement the behavior of the class and its objects. There are various types of classes that are used in real time applications such as nested classes, anonymous classes, lambda expressions.  Abstract Class  Abstract Class are classes that contain one or more abstract methods.  We use Abstract Class Because: An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.  How we use Class: An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this: abstract void moveTo(double deltaX, double deltaY); If a class includes abstract methods, then the class itself must be declared abstract, as in: public abstract class GraphicObject { // declare fields // declare nonabstract methods abstract void draw(); }
  • 2. 2 ថនសារិ When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.  Inheritance  inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the definitions of one or more general classes.  We use inheritance because: Inheritance is a term for reusing code by a mechanism of passing down information and behavior from a parent class to a child or sub class. It’s pretty easy to understand really. Just like a child can inherit various mannerisms and behaviors from his or her biological parents, in software this same concept holds true. By leveraging the power of inheritance and creating child classes that extend their parent, we can make sub classes with super powers that have everything their parent has and more. Let’s take a look at how inheritance works in PHP. II. Question  Singleton Vs Factory Method  Singleton  A singleton pattern ensures that you always get back the same instance of whatever type you are retrieving, whereas the factory pattern generally gives you a different instance of each type.  The purpose of the singleton is where you want all calls to go through the same instance. An example of this might be a class that manages a disk cache, or gets data from a static dictionary; wherever it is important only one known instance interacts with the resource. This does make it less scalable.  Factory Method:  Object creation without exposing in to client  Refer to newly created objects through interface  Define the interface for creating an object  The purpose of the factory is to create and return new instances. Often, these won’t actually be the same type at all, but they will be implementations of the same base class. However, there may be many instances of each type  Creational Vs Structural  Creational These design patterns provide ways to create objects while hiding the creation logic, instead of instantiating objects directly using the newoperator. This gives the program more flexibility in deciding which objects need to be created for a given use case.  Structural  These design patterns deal with class and object composition. The concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionality.  Structural Vs Behavioral  Structural Structural modelling refers to that type of modelling in which we simply interconnect the components by mapping there ports by seeing the rtl diagram whereas  Behavioral Behavioral modelling uses sequential statement inside the process statement ,in it we implement the logic directly and this modelling is preferred and is the highest level of abstraction
  • 3. 3 ថនសារិ  Strategy vs Command  Strategy Strategy, in contrasst, is used to customize an algorithm. A strategy might have a number of methods specific to the algorithm. Most often strategies will be instanciated immediately before executing the algorithm, and discarded afterwards.  Command Command encapsulates a single action. It therefore tends to have a single method with a rather generic signature. It often is intended to be stored for a longer time and to be executed later - or it is used to provide undo functionality (in which case it will have at least two methods, of course).  What is the benefit of  Singleton  Ensures only one instance of class is ever created  Can get access to data in this class from anywhere  Acts like global variables  Can cause methods to have unintended side-effects due to data sharing via state in the Singleton  Factory  Allows the sub-classes to choose the type of objects to create  Promoted the loose –coupling by eliminating the need to bind application-specific classes into the code .That mean the code interacts solely with the resultant interface or abstract class,so that it will work with any classes that implement that interface or that extends that abstract class.  Usage: 1. When a class doesn’t know what the sub-classes will be required to create 2. When a class want that it’s sub-classes specify the object to be created 3. When the parent class choose the creation of objects to its sub-classes  Strategy  Forces organizations to look ahead  Improved fit with the environment  Better use of resources  Provides a direction/vision  Helps monitor progress  Ensures goal congruence  Command  It decouples the classes that invoke the operation from the object that knows how to execute the operation  It allow you to create a sequence of command by providing a queue system  Extensions to add a new command is easy and can be done without changing the existing code  You can also define a rollback system with the command pattern.
  • 4. 4 ថនសារិ III. Coding  Factory Method  Strategy