For by preventing users from setting the internal data

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:

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!

order now











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:


means that the internal representation of an object is generally hidden from
view outside of the definition of the object. Typically, only the object’s own
methods can directly work with its fields.

is the hiding of data implementation by restricting access to accessors and

accessor is a method that is used to ask an object about itself. In OOP, these
are usually in the form of properties, which have a get method, which is an
accessor method. However, 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


abstraction and encapsulation are closely tied together, because a simple
definition of data abstraction is the development of classes, objects, types in
terms of their interfaces and functionality, instead of their implementation
details. Abstraction denotes a model, a view, or some other focused
representation for an actual item.

abstraction denotes the essential characteristics of an object that distinguish
it from all other kinds of object and thus provide crisply defined conceptual
boundaries, relative to the perspective of the viewer.” — G. Booch

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


is a way to reuse code of existing objects, or to establish a subtype from an
existing object, or both, depending upon programming language support. In
classical inheritance where objects are defined by classes, classes can inherit
attributes and behavior from pre-existing classes called base classes,
superclasses, parent classes or ancestor classes. The resulting classes are
known as derived classes, subclasses or child classes. The relationships of classes
through inheritance gives rise to a hierarchy.

and Superclasses A subclass 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


means one name, many forms. Polymorphism manifests itself by having multiple
methods all with the same name, but slightly different functionality.

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 Neil!

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

Check it out