For associated. In OOP, computer programs are

For this
project, I must develop some classes. The UML diagram of it included in the
file UML.png.

we can see, there we have ten classes:











So, what is Object-oriented programming (OOP)? It
is a programming paradigm based on the concept of objects. Objects may contain
data, in the form of fields, often known as attributes. Also, they may contain code,
in the form of procedures, often known as methods. A feature of objects is that
an object’s procedures can access and often modify the data fields of the
object with which they are associated. In OOP, computer programs are designed
by making them out of objects that interact with one another.

So, every
class of my program describes some object, like User, Item, Supplier, etc. Only
two classes are used for providing only methods. They are and
The first of them is used for interacting with a user with the help of
Terminal. The second is used for writing and reading information from files.

There are 4
main principles of OOP.

1.       Encapsulation:


in Java is a mechanism of wrapping the data (variables) and code acting on the
data (methods) together as a single unit. In encapsulation, the variables of a
class will be hidden from other classes, and can be accessed only through the
methods of their current class. Therefore, it is also known as data hiding.

achieve encapsulation in Java ?


Declare the variables of a class as private.


Provide public setter and getter methods to modify and
view the variables values.

accessor methods are not restricted to properties and can be any public method
that gives information about the state of the object.

Mutator is a public method that is used to modify the state of an object while
hiding the implementation of exactly how the data gets modified. It’s the set
method that lets the caller modify the member data behind the scenes.

the internals of the object protects its integrity by preventing users from
setting the internal data of the component into an invalid or inconsistent
state. This type of data protection and implementation protection is called

A benefit
of encapsulation is that it can reduce system complexity.

provides a number of access modifiers to set access levels for classes,
variables, methods, and constructors. The four access levels are ?

Visible to the package, the default. No modifiers are

Visible to the class only (private).

Visible to the world (public).

Visible to the package and all subclasses (protected).

All classes
of my project, that describes objects, all variables are private. So they may
be accessed only with the help of methods of this class. So, we cannot change
any field of object of classes for Item, Supplier, Purchase Requisition,
Purchase Order, Daily Item-Wise Sales, or User from TBS class, which contains
this objects. In Purchase Order class, for example, I have next private fields:



     * List of


    private ArrayList itemCodes;



     * Quantity
of items


    private HashMap quantity;



     * Date


    private String dateRequired;



     * ID of
Purchase Order


    private String id;



     * Sales
Manager, who adds this Purchase Order


    private User salesManager;


It is
possible to change their value only with the help of special method of this
classes, they are called mutators (for example


     * Setter

     * @param


    public void setCode(String code) {

= code;


method in
Item class). For getting values from private variables there are special
methods, which are called accessors (for example


     * Getter

     * @return


    public ArrayList getItems() {

        return items;



which gives
access to the Items list from class, that represents Daily Item-Wise Sales). Also, there are some private methods,


     * Adds
users from file to list

     * @throws


    private void addUsersFromFile() throws IOException {

        for (String s :
FileUtils.readFile(“Users.txt”)) {

String values = s.split(“,”);

users.add(new User(values0, values1,



class. So we can use this method only in this class. With the help of
encapsulation, I protect object’s variables from unauthorized changes,
which may crash the program.

2.       Abstraction


is the quality of dealing with ideas rather than events. For example, when you
consider the case of e-mail, complex details such as what happens as soon as
you send an e-mail, the protocol your e-mail server uses are hidden from the
user. Therefore, to send an e-mail you just need to type the content, mention
the address of the receiver, and click send.


in Object-oriented programming, abstraction is a process of hiding the
implementation details from the user, only the functionality will be provided
to the user. In other words, the user will have the information on what the
object does instead of how it does it.


In Java,
abstraction is achieved using Abstract classes and interfaces. In short, data
abstraction is nothing more than the implementation of an object that contains
the same essential properties and actions we can find in the original object we
are representing.

In my
project, there is no abstraction because we don’t have any standard interface for

3.       Inheritance


process by which one class acquires the properties(data members) and functionalities(methods)
of another class is called inheritance. The aim of inheritance is to provide
the reusability of code so that a class has to write only the unique features
and rest of the common properties and functionalities can be extended from the another

Child Class:

class that extends the features of another class is known as child class, sub
class or derived class.


Parent Class:

The class
whose properties and functionalities are used(inherited) by another class is
known as parent class, super class or Base class.

Child and Parent
classes is a modular, derivative class that inherits one or more properties
from another class (called the superclass). The properties commonly include
class data variables, properties, and methods or functions. The superclass
establishes a common interface and foundational functionality, which
specialized subclasses can inherit, modify, and supplement. The software
inherited by a subclass is considered reused in the subclass. In some cases, a
subclass may customize or redefine a method inherited from the superclass. A
superclass method which can be redefined in this way is called a virtual

So, there are
not any similar classes in my project, that is why I did not use inheritance.
It is possible to create parent class like for
and classes, they have similar fields and methods, but
this is different documents and we don’t need to incorporate them. But all
classes in Java are inherited from Object class. So, I can say, that I use
inheritance, but it is invisible.

4.       Polymorphism


is the ability of an object to take on many forms. The most common use of
polymorphism in OOP occurs when a parent class reference is used to refer to a
child class object. There are 2 basic types of polymorphism. Overriding also
called run-time polymorphism. For method overloading, the compiler determines
which method will be executed, and this decision is made when the code gets
compiled. Overloading, which is referred to as compile-time polymorphism. The method
will be used for method overriding is determined at runtime based on the
dynamic type of an object.

If you can
grasp these four principles, OOP can be much of a breeze for you. It might take
more than one read, I encourage you to practically try it.

is closely connected with inheritance. We are able to Override methods of the parent
class. As all classes in Java are inherited from Object class, that is why we
can override Object’s methods. In my project, I override toString() method.
This method returns a string representation of the object. In general, the
toString method returns a string that “textually represents” this
object. The result should be a concise but informative representation that is
easy for a person to read. It is recommended that all subclasses override this

toString method for class Object returns a string consisting of the name of the
class of which the object is an instance, the at-sign character `@’, and the unsigned
hexadecimal representation of the hash code of the object. In other words, this
method returns a string equal to the value of:


 getClass().getName() + ‘@’ +


But we need
a more convenient string representation of the object. For example, in Purchase
Order class toString() method is overridden in a next way.


    public String toString() {

itemsIDs = “”;

total = “”;

        for (String item : itemCodes)

itemsIDs += item + “,”;

total += quantity.get(item) + “,”;


= itemsIDs.substring(0, itemsIDs.length() – 1);

        total =
total.substring(0, total.length() – 1);

        return dateRequired +

+ purchaseManager.getLogin() + ”
” +
itemsIDs + ”
” + total;



So, the string, which represents the object of this
class in a next way. The first element is the date when this Order is needed.
The next, which is after the symbol of the new line, is login of Purchase
manager, who has added this order. Then there are IDs of items, which are
needed and the quantity of every item.


I'm Mary!

Would you like to get a custom essay? How about receiving a customized one?

Check it out