You are on page 1of 11

QUARTER 3

MODULE 6
Computer Programming (Java) – Grade 12
Quarter 3 – Module 6: Object Oriented Design Principles in Java

First Edition, 2020

Republic Act 8293, Section 176 states that no copyright shall subsist in any
work of the Government of the Philippines. However, prior approval of the
government agency or office wherein the work is created shall be necessary for
exploitation of such work for profit. Such agency or office may, among other things,
impose as a condition the payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand


names, trademarks, etc.) included in this module are owned by their respective
copyright holders. Every effort has been exerted to locate and seek permission to use
these materials from their respective copyright owners. The publisher and authors
do not represent nor claim ownership over them.

Published by the Department of Education - Schools Division of Pasig City

Development Team of the Self-Learning Module


Writer: Paola T. Galario
Editor: Mrs. Lerma O. Cantanero
Reviewers: Mrs. Rowena O. Dimagiba
Illustrator:
Layout Artist:
Management Team: Ma. Evalou Concepcion A. Agustin
OIC-Schools Division Superintendent
Aurelio G. Alfonso EdD
OIC-Assistant Schools Division Superintendent
Victor M. Javeña EdD
Chief, School Governance and Operations Division and
OIC-Chief, Curriculum Implementation Division

Education Program Supervisors

Librada L. Agon EdD (EPP/TLE/TVL/TVE)


Liza A. Alvarez (Science/STEM/SSP)
Bernard R. Balitao (AP/HUMSS)
Joselito E. Calios (English/SPFL/GAS)
Norlyn D. Conde EdD (MAPEH/SPA/SPS/HOPE/A&D/Sports)
Wilma Q. Del Rosario (LRMS/ADM)
Ma. Teresita E. Herrera EdD (Filipino/GAS/Piling Larang)
Perlita M. Ignacio PhD (EsP)
Dulce O. Santos PhD (Kindergarten/MTB-MLE)
Teresita P. Tagulao EdD (Mathematics/ABM)

Printed in the Philippines by Department of Education – Schools Division of


Pasig City
Computer
Programming
QUARTER 3
+
MODULE

6 Object Oriented Design


Principles in Java

Writer : Paola T. Galario


Editor : Mrs. Lerma O. Cantanero
Reviewers : Mrs. Rowena O. Dimagiba
Introductory Message

For the Facilitator:

Welcome to the Computer Programming (Java) 12 Self-Learning Module on


Object Oriented Design Principles in Java!

This Self-Learning Module was collaboratively designed, developed and


reviewed by educators from the Schools Division Office of Pasig City headed by its
Officer-in-Charge Schools Division Superintendent, Ma. Evalou Concepcion A.
Agustin, in partnership with the City Government of Pasig through its mayor,
Honorable Victor Ma. Regis N. Sotto. The writers utilized the standards set by the K
to 12 Curriculum using the Most Essential Learning Competencies (MELC) in
developing this instructional resource.

This learning material hopes to engage the learners in guided and independent
learning activities at their own pace and time. Further, this also aims to help learners
acquire the needed 21st century skills especially the 5 Cs, namely: Communication,
Collaboration, Creativity, Critical Thinking, and Character while taking into
consideration their needs and circumstances.

In addition to the material in the main text, you will also see this box in the
body of the module:

Notes to the Teacher


This contains helpful tips or strategies that
will help you in guiding the learners.

As a facilitator you are expected to orient the learners on how to use this
module. You also need to keep track of the learners' progress while allowing them to
manage their own learning. Moreover, you are expected to encourage and assist the
learners as they do the tasks included in the module.
For the Learner:

Welcome to the Computer Programming (Java) 12 Self-Learning Module on


Object Oriented Design Principles in Java!

This module was designed to provide you with fun and meaningful
opportunities for guided and independent learning at your own pace and time. You
will be enabled to process the contents of the learning material while being an active
learner.

This module has the following parts and corresponding icons:

Expectations - This points to the set of knowledge and skills


that you will learn after completing the module.

Pretest - This measures your prior knowledge about the lesson


at hand.

Recap - This part of the module provides a review of concepts


and skills that you already know about a previous lesson.

Lesson - This section discusses the topic in the module.

Activities - This is a set of activities that you need to perform.

Wrap-Up - This section summarizes the concepts and


application of the lesson.

Valuing - This part integrates a desirable moral value in the


lesson.

Posttest - This measure how much you have learned from the
entire module.
EXPECTATIONS

After completing this lesson, you should be able to:

1. describe the Object Oriented Design Principles in Java,


2. understand the benefits of Object Oriented Design Principles in coding,
and
3. apply the concept of Object Oriented Design Principles in accordance to
Java framework.

PRETEST

DIRECTIONS: Identify the following Object Oriented Design Principle. Write your
answer on the space provided.
__________ 1. This principle states that there should never be two functionalities in
one class.
__________ 2. This principle is closely related to The Interface Segregation Principle
and The Single Responsibility Principle.
__________ 3. This design principle is no duplication of code and pretty easy to modify
behaviour.
__________ 4. This object oriented design principle which prevents someone from
changing already tried and tested code.
__________ 5. These are generalized pieces of advice or proven good coding practices
that are used as rules of thumb when making design choices.

RECAP
DIRECTIONS: On the space provided, discuss and enumerate what you have learned
from the previous lesson.
LESSON

Object Oriented Design Principles

Design Principles are generalized pieces of advice or proven good coding


practices that are used as rules of thumb when making design choices. They're a
similar concept to design patterns, the main difference being that design principles
are more abstract and generalized. They are high-level pieces of advice, often
applicable to many different programming languages or even different paradigms.

Design patterns are also abstractions or generalized good practices, but they
provide much more concrete and practical low-level advice, and are related to entire
classes of problems rather than just generalized coding practices. Some of the most
important design principles in the object oriented paradigm are listed below:

Don't Repeat Yourself (DRY) Principle

The Don't Repeat Yourself (DRY) principle is a common principle across


programming paradigms, but it is especially important in OOP. As name suggest
DRY (don't repeat yourself) means don't write duplicate code, instead use
abstraction to abstract common things in one place. If you use a hardcoded value
more than one time consider making it public final constant, if you have block of
code in more than two place consider making it a separate method. Benefit of this
SOLID design principle is in maintenance.

Encapsulate what varies

Only one thing is constant in software field and that is "Change", So


encapsulate the code you expect or suspect to be changed in future. Benefit of this
OOPS Design principle is that it’s easy to test and maintain proper encapsulated
code. If you are coding in Java then follow principle of making variable and methods
private by default and increasing access step by step e.g. from private to protected
and not public.

The Open/Closed Principle

Classes, methods or functions should be Open for extension (new


functionality) and Closed for modification. This is another beautiful object oriented
design principle which prevents someone from changing already tried and tested
code. Ideally if you are adding new functionality only than your code should be tested
and that's the goal of Open Closed Design principle.

The Single Responsibility Principle (SRP)

There should not be more than one reason for a class to change or a class
should always handle single functionality. If you put more than one functionality in
one Class in Java it introduce coupling between two functionality and even if you
change one functionality there is chance you broke coupled functionality which
require another round of testing to avoid any surprise on production environment.

The Dependency Inversion Principle (DIP)

According to the Dependency Inversion Principle (DIP), high-level and low-level


modules should be decoupled in such a way that changing (or even replacing) low-
level modules doesn't require (much) rework of high-level modules. Given that, both
low-level and high-level modules shouldn't depend on each other, but rather they
should depend on abstractions, such as interfaces.

The Composition Over Inheritance Principle

One should often prefer composition over inheritance when designing their
systems. In Java, this means that we should more often define interfaces and
implement them, rather than defining classes and extending them.

Liskov Substitution Principle (LSP)

According to the Liskov Substitution Principle (LSP), derived classes should


be able to substitute their base classes without the behavior of your code changing.
This principle is closely related to The Interface Segregation Principle and The Single
Responsibility Principle, meaning that a violation of either of those is likely to be (or
become) a violation of LSP as well. This is because if a class does more than one
thing, subclasses extending it are less likely to meaningfully implement those two or
more functionalities.

The Interface Segregation Principle (ISP)

The Interface Segregation Principle (ISP) states that the client should never be
forced to depend on an interface they aren't using in its entirety. This means that an
interface should have a minimum set of methods necessary for the functionality it
ensures, and should be limited to only one functionality.

Programming for Interface not Implementation

Always program for interface and not for implementation this will lead to
flexible code which can work with any new implementation of interface. So use
interface type on variables, return types of method or argument type of methods in
Java.

Delegation Principle

Don't do all stuff by yourself, delegate it to respective class. Classical example


of delegation design principle is equals() and hashCode() method in Java. In order to
compare two object for equality we ask class itself to do comparison instead of Client
class doing that check. Benefit of this design principle is no duplication of code and
pretty easy to modify behaviour.
ACTIVITIES

DIRECTIONS: Create a simple code/program that would integrate at least 5 different


Object Oriented Design Principles and explain the flow of your Program including the
Design Principle that you use.

RUBRICS:
10 8 5 1
The program The program The program The program
showed at least 5 showed 3 different showed only 2 showed none of
different Design Design Principle different Design any of the Design
Principle and has and somewhat Principle and Principle and no
explanation complete incomplete explanation
explanation

WRAP-UP

Object Oriented Design Principles


Design Principles are generalized pieces of advice or proven good coding
practices that are used as rules of thumb when making design choices. They're a
similar concept to design patterns, the main difference being that design principles
are more abstract and generalized.

Object Oriented Design Description


Principles (Your own Perception base on the discussion)
Don’t Repeat Yourself (DRY)
Encapsulate what varies
The Open/Close Principle
Delegation Principle
The Interface Segregation
Principle (ISP)
Programming for Interface
not Implementation
Liskov Substitution
Principle (LSP)
The Dependency Inversion
Principle (DIP)
The Composition over
Interface Principle
The Single Responsibility
Principle
VALUING

DIRECTIONS: Answer the following questions below, and write your answer in the
space provided.

1. Based on what you have learned in this lesson, what do you think is importance
of Design Principle in your program? What makes it easier to do something when
you follow the Principles?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

POST-TEST

DIRECTIONS: Identify whether each statement is True or False.

_________ 1. Do all the stuff by yourself and do not delegate it to the other class.
_________ 2. One should often prefer composition over inheritance when designing
their systems.
_________ 3. The acronym “DRY” in the Object Oriented design Principles means
Don’t Ruin Yourself.
_________ 4. The design principle are more abstract and generalized.
_________ 5. The Interface Segregation Principle (ISP) states that the client should
be forced to depend on an interface they are using in its entirety.
KEY TO CORRECTION
5. Design Principles 5. FALSE
4. The Open/Closed Principle 4. TRUE
3. The Delegation Principle 3. FALSE
2. Liskov Substitution Principle 2. TRUE
1. The Single Responsibility Principle 1. FALSE
PRE TEST POST TEST

References
Websites:
10 Object-Oriented (OOP) Design Principles Java Programmers Should Know,
Accessed January 11, 2021, 02:15:45 PM, shorturl.at/ikCG5

Object Oriented Design Principles in Java, Accessed January 12, 2021, 11:05:13
AM, https://stackabuse.com/object-oriented-design-principles-in-java/

10 Object Oriented Design principles Java programmer should know (guest


post), January 12, 2021, 03:45:06 PM ,
https://javarevisited.blogspot.com/2018/07/10-object-oriented-design-
principles.html

You might also like