Major Principles Of Object Oriented Programming English Language Essay

Published:

Four majar principle of Object oriented programmers new OOP, this article will briefly explain the four basic principles that make object-oriented language: Encapsulation, data abstraction, polymorphism and inheritence. All examples in VB.Net, because I think it is easier for new programmers to read and understand OOP first. Of course, I do not think that means you have to use one. NET-based language to another, and all on / CLR CLS language and at the end of the form assembly. Indicating your preference, what language you use. Of course, there are others out there OOP languages such as Ruby, pure OOP language, and hybrid languages such as Python, C and Java to mention a few

Encapsulation:

What is encapsulation? Well, in a nutshell, encapsulation is hiding data using limiting access to accessors and mutators. First, it allows you to define the accessors and mutator.

accessor Accessor standard procedure to ask any questions about himself. OOP, it is usually with the form of properties under normal conditions, have a method which is the accessor method. However, accessor method is not limited to the features can be in any public way that the information on the status object

Lady using a tablet
Lady using a tablet

Professional

Essay Writers

Lady Using Tablet

Get your grade
or your money back

using our Essay Writing Service!

Essay Writing Service

Public Class Person

'We use Private here to hide the implementation of the objects

' fullName, which is used for the internal implementation of Person.

Private _fullName As String = "Raymond Lewallen"

' This property acts as an accessor.  To the caller, it hides the

' implementation of fullName and where it is set and what is

' setting its value. It only returns the fullname state of the

' Person object, and nothing more. From another class, calling

' Person.FullName() will return "Raymond Lewallen".

' There are other things, such as we need to instantiate the

' Person class first, but thats a different discussion.

Public ReadOnly Property FullName() As String

Get

Return _fullName

End Get

End Property

End Class

Mutator:

Mutators public methods used to change the state object, and hide the implementation of the right how to get the data has changed. Mutators are usually part of the property discussed above, only this time its the method allows the caller to change the data members behind the scenes

Public Class Person

    ' We use Private here to hide the implementation of the objects  

    ' fullName, which is used for the internal implementation of Person.

    Private _fullName As String = "Raymond Lewallen"

 

    ' This property now acts as an accessor and mutator.  We still  

    ' have hidden the implementation of fullName.

    Public Property FullName() As String

        Get

            Return FullName

        End Get

        Set(ByVal value As String)

            _fullName = value

        End Set

    End Property

End Class

Ok, now lets look at a different example that contains an accessor and a mutator:

Public Class Person

    Private _fullName As String = "Raymond Lewallen"

 

    ' Here is another example of an accessor method,  

    ' except this time we use a function.

    Public Function GetFullName() As String

        Return _fullName

    End Function

 

    ' Here is another example of a mutator method,  

    ' except this time we use a subroutine.

    Public Sub SetFullName(ByVal newName As String)

        _fullName = newName

    End Sub

 

End Class

Therefore, the use of accessors and mutators offers many advantages. Hiding the implementation of our class of person, we can make changes in the classroom without the fear of man, that we are going to break the code reader using human status information. If we want we can FULLNAME a line in a array of individual characters (Note that this is a string object is actually behind the scenes), but they never call him, I know that we still want them back FULLNAME per line, but behind the scenes we have to deal with the array of characters instead of the string element. Transparent the rest of his program. Type of data protection and protection is sought is called Encapsulation. Thinking of accessors and mutators such pieces, which are surrounded by the form of data classes.

Abstraction.

Lady using a tablet
Lady using a tablet

Comprehensive

Writing Services

Lady Using Tablet

Plagiarism-free
Always on Time

Marked to Standard

Order Now

Data abstraction to understand the simplest principles. Encapuslation data abstraction are closely related to each other, the simple definition of data abstraction to create objects of class types of interfaces in terms of their functionality, not implementation details. Model shows, abstraction, landscape, or some other focused representation for the actual item. Development of the software object that represents something we can find the real world. Encapsulation hides the implementation details.

Abstraction is used to manage complexity. Software developers to use abstraction to break complex systems into small parts. As the development of progresss, programmers can learn the functionality they expect still undeveloped sub. Consequently, programmers are not taken by the discussion waysin subsystesm late application will design early development.

The best definition of abstraction ever read is "abstraction means something significant to distinguish the characteristics of other types of sharp objects to provide the conceptual boundaries relative to the viewer's perspective" - G. Booch, Object oriented design: Benjamin, for the simple / Cummings, Menlo Park, California, 1991.

Allows you to look for in this Code otherwise. What are some things you can do: It must be represented here in our software model of a person. Things I am, how tall a person, at the age of man, we need to see them. We have the ability to people to do things like running away. We should be able to ask people if they can read.

Public Class Person

 

    Private _height As Int16

    Public Property Height() As Int16

        Get

            Return _height

        End Get

        Set(ByVal Value As Int16)

            _height = Value

        End Set

    End Property

 

    Private _weight As Int16

    Public Property Weight() As Int16

        Get

            Return _weight

        End Get

        Set(ByVal Value As Int16)

            _weight = Value

        End Set

    End Property

 

    Private _age As Int16

    Public Property Age() As Int16

        Get

            Return _age

        End Get

        Set(ByVal Value As Int16)

            _age = Value

        End Set

    End Property

 

    Public Sub Sit()

        ' Code that makes the person sit

    End Sub

 

    Public Sub Run()

        ' Code that makes the person run

    End Sub

 

    Public Sub Cry()

        ' Code that make the person cry

    End Sub

 

    Public Function CanRead() As Boolean

        ' Code that determines if the person can read

        ' and returns a true or false

    End Function

 

End Class

So, we have started to create a software model of human things, we created a summary of what we want the man out of the software world. Abstract human is determined by the actions that can be carried out, the information we can get them to let them. What is looking, heedless of human affairs as the world software to take advantage of its internal workings? Looks like this:

 

You can not really see what the code that makes people run. We discuseed encapsulation.

Thus, in short, data abstraction is nothing more than to implement anything that contains the same essential qualities and actions that we can find the original object of the present.

Mana:

Now allows you to discuss the succession. Things may be related to eachother with "There", "on" or "relationship. "Is the" object-relations method inherently example of this has always stuck with me during the years of the library (I think it can read anything, Grady Booch wrote:) So, from a library, for example, the Library lends more than just books, but also provides magazines, audiocassettes and microfilm. some level, all these elements can be the same for all four types of assets represent the library that may be it is pay, but even 4 types can be seen, they are not identical . ISBN book and magazine are not. And audiocassette has a long play microfilm can not check the night.

Library of assets must be represented by its own procedures. Inheritance is that each class should be implemented regardless of the attributes of all loanable assets. The whole property is also examined, or are available as foundation. All properties have a name, date of purchase and value of change. Duplicating the functionality, instead, inheritance allows you to inherit the role of another class, called superclass or base class.

Lady using a tablet
Lady using a tablet

This Essay is

a Student's Work

Lady Using Tablet

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Examples of our work

We expect the Department property loanable base. He serves as a basis for the class of property such as books and audiocassette.

Inheritance:

Inheritance is that each class should be implemented regardless of the attributes of all loanable assets. The whole property is also examined, or are available as foundation. All properties have a name, date of purchase and value of change. Duplicating the functionality, instead, inheritance allows you to inherit the role of another class, called superclass or base class.

We expect the Department property loanable base. He serves as a basis for the class of property such as books and audiocassette

Inheritance relationship is called "she" relationship. "Book of« LibraryAsset, as well as the other 3 properties.

Let's look at the school classes that are inherited class LibraryAsset audiocassette out.

Public Class LibraryAsset

 

    Private _title As String

    Public Property Title() As String

        Get

            Return _title

        End Get

        Set(ByVal Value As String)

            _title = Value

        End Set

    End Property

 

    Private _checkedOut As Boolean

    Public Property CheckedOut() As Boolean

        Get

            Return _checkedOut

        End Get

        Set(ByVal Value As Boolean)

            _checkedOut = Value

        End Set

    End Property

 

    Private _dateOfAcquisition As DateTime

    Public Property DateOfAcquisition() As DateTime

        Get

            Return _dateOfAcquisition

        End Get

        Set(ByVal Value As DateTime)

            _dateOfAcquisition = Value

        End Set

    End Property

 

    Private _replacementCost As Double

    Public Property ReplacementCost() As Double

        Get

            Return _replacementCost

        End Get

        Set(ByVal Value As Double)

            _replacementCost = Value

        End Set

    End Property

Polymorphism

Polymorphism means many forms there. Polymorphism is expressed by a number of methods all of the same name, but slighty different roles. Many people are familiar with the interface VB6ers polymorphism. I'm just going to consider the viewpoint of polymorphism, inheritance, that is part of this is new to many people. Therefore, it may be difficult to fully grasp all the potential Polymorphism, until you get some practice with it and see what is happening right under different scenarios. We are just going to talk about polymorphism, as well as other issues, the main level.

There are two main types of polymorphism. Overridding, as well as called Runtime polymorphism, and overloading, which is called compile time polymorphism. This difference for overloading the system, the compiler determines that the method is carried out, and that decision was made when the code gets formed. Method used to overriding methods Runtime determined depending on the type object dynamically.

Public MustInherit Class LibraryAsset

 

    ' Default fine per day for overdue items

    Private Const _finePerDay As Double = 1.25

 

    ' Due date for an item that has been checked out

    Private _dueDate As DateTime

    Public Property DueDate() As DateTime

        Get

            Return _dueDate

        End Get

        Set(ByVal Value As DateTime)

            _dueDate = Value

        End Set

    End Property

 

    ' Calculates the default fine amount for an overdue item

    Public Overridable Function CalculateFineTotal() As Double

        Dim daysOverdue As Int32 = CalculateDaysOverdue()

        If daysOverdue > 0 Then

            Return daysOverdue * _finePerDay

        Else

            Return 0.0

        End If

    End Function

 

    ' Calculates how many days overdue for an item being returned

    Protected Function CalculateDaysOverdue() As Int32

        Return DateDiff(DateInterval.Day, _dueDate, DateTime.Now())

    End Function

 

End Class

 

' Magazine class that inherits LibraryAsset

Public NotInheritable Class Magazine

    Inherits LibraryAsset

 

End Class

 

' Book class that inherits LibraryAsset

Public NotInheritable Class Book

    Inherits LibraryAsset

 

    ' This is morphing the CalculateFineTotal() function of the base class.

    ' This function overrides the base class function, and any call

    '   to CalculateFineTotal from any instantiated Book class will

    '   use this function, not the base class function.

    ' This type of polymorphism is called overriding.

    Public Overrides Function CalculateFineTotal() As Double

        Dim daysOverdue As Int32 = CalculateDaysOverdue()

        If daysOverdue > 0 Then

            Return daysOverdue * 0.75

        Else

            Return 0.0

        End If

    End Function

Components involved in OOP:

Components: objects, classes (public and private), methods (public, private), Collect variable (public, private);

Object is key to understanding object-oriented technology. Look around today you will find examples of real world objects: your dog, your desk, your television, your bicycle.

Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, race, hungry) and behavior (see, pick up, wagging his tail.) Bicycles state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Conduct Mode identification for real objects in the world is a great way to start thinking in terms of object oriented programming.

Take a minute today to consider real world objects in your immediate area. Every item you see, ask yourself two questions: "What are the possible situations may object that" and "What are behaviors that can be done on this object": Be sure to write observations: How do you do, you will notice that objects in the real world vary in complexity, your working table lamps can be only two possible states (on and off) and two possible behaviors (turn, turn), but the radio on your desktop, maybe more countries (on, off, volume current, the current station) and behavior (all, in turn, increase volume, decrease volume, seek, scan, and music) you can also notice that some elements, in turn, also contain other objects with the real observations the world, all object-oriented programming.

Software objects in a conceptual real-world objects they contain are subject to state and behavior. One thing that stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages). The object of internal procedures to be used for the main mechanism for communication and object-object. Hiding the internal state demands that all interaction must be made by the well-known method of data object encapsulation is a fundamental principle in object oriented programming.

I think bicycle, for example,

Software object model bike.

By attributing the state (current speed, current pedal cadence, and the current equipment and provide methods to change the situation, the item is still in control of how the outside world can use it. For example, if the bike has 6 gears, a way to change gears can reject any amount less than 1 or more than 6.

Bundling code into individual software objects provides a number of advantages, including:

1. Modularity `source code for something that may be in writing and keep the code independent of other things. Once created, objects can be moved easily around the system.

2. Hiding information by interacting only a matter of procedure, details of internal implementation remain hidden to the outside world.

3. Code reuse: If there is something (perhaps written by another Programmer), you can use it in your program. This allows experts to carry out / testing / debugging, the problem of special complex elements that you can trust run your code.

4. Pluggability easily bug: If the material turns to a problem, you can simply remove it from your application to plug in different things in place. This is similar to repair mechanical problems in the real world. If a bolt breaks you replace it, but not the whole car.

What class.

Real world, you often find many individual objects of the same type. Maybe there are thousands of other bikes of its existence, nevertheless model. Bike all build the same number of images and contains the same elements. Object-oriented terms, we say that your bicycle is such a class of objects known as the bicycle. A detailed program, for which only the object is created.

The following Bicycle class is one possible implementation of a bicycle:

class Bicycle {

int cadence = 0;

int speed = 0;

int gear = 1;

void changeCadence(int newValue) {

cadence = newValue;

}

void changeGear(int newValue) {

gear = newValue;

}

void speedUp(int increment) {

speed = speed + increment;

}

void applyBrakes(int decrement) {

speed = speed - decrement;

}

void printStates() {

System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear);

}

}

That sharahyusakan the programming language Java will look new to you, but the design is based on the lessons of previous discussions of bike stuff. Field rate, speed, mechanisms, representing a state object, and the procedure (changeCadence, changeGear acceleration etc.) determines its interaction with the outside world.

You may have noticed that the Bicycle class contains the main method. This is because full implementation, it only provides for a bicycle to be used in the application. Responsibility to create and use the bike a few new things that belong to other classes in your application.

Here is the class BicycleDemo to create two separate objects and their methods of operating a bicycle.

What is the object

object is introduced to the field, but you probably have some questions, such as: What are the rules and conventions by giving the field: Int Besides, what other kinds of available data fields must be initialized, when they are told, to get a default value if they are explicitly initialized: We will explore questions such class, but before we do, there are some technical differences, you first need to obtain knowledge. Programming language Java, providing "field" and "changes" are not used as a common source of confusion among new developers, as they often seemed to refer to the same thing.

Java programming language defines the following types of variables.

• Examples and variable (No Static fields) Technically, that store their individual states non-static fields ", ie, fields declared without the static Home Results. Non-static fields are also called, for instance variables because their values are unique for each instance of a class (for each object, or in other words), currentSpeed bike currentSpeed independent from others.

• You have a variable (static fields) changes in the classroom, in any area declared static thing that means the compiler has a copy of life changes, no matter how many times it shows class. Decision number field for the gears of certain types of bicycle can be marked as static, as the concept will apply the same number of gears in all circumstances. Static int NumGears code = 6; create such a static field. In addition, the final keyword can be added to specify the number will not change gears.

• Local variables like how to store object in its field, the weather often store its temporary state in local variables. That sharahyusakan declare a local variable declaration appears in a field (eg, int count = 0;) There is no special keyword designating a variable as local, self-determination comes entirely from the location where the variable is declared - that is opening and closing braces of a method. As such, local variables are visible only way that they are expressed, they are not available in other grades.

• Indicators that you have seen examples of parameters are the main means of bicycle class «Hello world!" Application. Let us remember that by signing the main method public static void Main (string [args]). Here, the variable is args parameters to this method: The most important to remember is that the parameters are always classified as "variable," no "field" This applies to adopt the other parameter, and constructs (such as constructors and exception handlers), which you learn later in this guide.

Having said that the rest of this tutorial uses the following general guidelines when discussing the changing field. If we speak of "common field" (not including local variables and parameters), we can only say, "field". If the discussion is applicable to "all the above, we can just say" change. " If the geographical context requires a distinction, we use special terms for static fields, local variables, etc.) as needed. You may also from time to time to see the "member" (a term, as well. a number of fields, methods, and nested types collectively called its members.

Low

Any programming language has its own rules and conventions for the types of names you can use, and programming language Java is no different. Rules and conventions for giving your variables may be summarized as follows:

• variable names are case-sensitive. Variable name can be any legal identification, and unlimited length sequence of Unicode letters and digits, starting with a letter, dollar sign "$" or underline "_" character. Convention, however, always start your letter variable name and not "$" or "_". Moreover, the dollar sign character, according to the convention, not used by all. You can find some situations where auto-generated name contains a dollar sign, but your variable names should always avoid using it. Is there a bottom to the Convention, and it is technically illegal in your variable names start with "_", this practice is discouraged. White spaces are not allowed.

• The following characters can be letters, numbers, dollar signs, or the importance of heroes. Conventions (and common sense) also apply to this rule. When you select a name for your variables, use full words instead of arcane acronyms. Doing so will make your code easier to read and understand. In many cases it will be your code self-documentation, the name of a field rate of speed, and equipment, for example, more intuitive than abbreviated versions, such as c s, and G. Also note that the name you choose must not be words or reserved words.

• If the name that you made just one word, spell that word in all lowercase letters. If it consists of more than one word, the first letter of each word below. Names currentGear gearRatio example of the Prime Minister of this Convention. If your variable stores a permanent value, such as static final int NUM_GEARS = 6, contract changes, and any separate letter to the following words with underscores. According to convention, emphasized not used elsewhere.

Set by

Here is an example of a typical method came haytarararutyamb.

calculateAnswer public Double (double wingspan, numberOfEngines length int double double grossTons) {

/ Is the math here

}

Only the necessary elements of sex the way back to the statement, so a pair of parentheses (), and body between braces, {}.

More generally, since the declaration has six parts, so that:

1. Components, such as public, private, and others, can be found later.

2. Type of data type values back to the way back, or void if the method does not return value.

3. Name system, domain name rules apply to the method name, as well as the Convention but are a little different.

4. Parameters in a comma list of parentheses-divided list of input parameters, preceded by their data types, surrounded by parentheses (). If no parameters, you must use empty parentheses.

5. List of exceptions, which will be discussed later.

6. Method body, enclosed between braces method - code, including the declaration of local variables, here we go.

Components, return type, and parameters are discussed later in this lesson. Exceptions are discussed in a later lesson.

 

Definition: two parts of method declaration in method name, signature of the method parameter types.

 

Signature method is not listed above.

calculateAnswer (double, int, double-double.

Method of giving

Although the method name can be any legal identification, code conventions limit the name method. The names of the Convention method should work in small print or multiple-word name that starts with a lowercase verb followed by the titles, nouns, etc. multi word 'genocide' names, the first letter of each word should be capitalized. Here are a few examples.

Run

runFast

getBackground

getFinalData

compareTo

setX

isEmpty

Usually, the weather has a unique name within its class. However, one way may have the same name, otherwise, because the way drive.

Overloading Methods:

Programming language Java Super supports methods, and Java can distinguish between methods of different ways to sign it. This means that the methods of a class may have the same name, if they have a different list of parameters (some qualifications discussed in this lesson titled "interfaces Muchacha").

Suppose you have a lesson that can be used for calligraphy painted in different types of data (strings, integers, etc.), which contains a drawing method for each type of data. It is difficult to use a new name for each mode, for example, string, drawInteger, drawFloat, and so on. Programming language Java, you can use the same name all the methods of paint, but switch to a different argument list in every way. Therefore, the data can be expressed in four methods of drawing class is called a draw, each one has a list of different parameters.

{Public class DataArtist

...

Public void draw (String s) {

...

}

Draw public places (int i) {

...

}

Public void draw (double f) {

...

}

Public void draw (int i double f) {

...

}

}

Overloaded method is different from the number and type of arguments contained in these ways. Code sample, draw (String s) and draw (int i) is different and unique, because they require different kinds of requirements.

You can not express more than one method of the same name and same type of arguments that the compiler can not tell their addition.

Naming:

Every programming language has its own set of rules and conventions for the kinds of names that you're allowed to use, and the Java programming language is no different. The rules and conventions for naming your variables can be summarized as follows:

Variable names are case-sensitive. A variable's name can be any legal identifier - an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.

Subsequent characters may be letters, digits, dollar signs, or underscore characters. Conventions (and common sense) apply to this rule as well. When choosing a name for your variables, use full words instead of cryptic abbreviations. Doing so will make your code easier to read and understand. In many cases it will also make your code self-documenting; fields named cadence, speed, and gear, for example, are much more intuitive than abbreviated versions, such as s, c, and g. Also keep in mind that the name you choose must not be a keyword or reserved word.If the name you choose consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, capitalize the first letter of each subsequent word. The names gearRatio and currentGear are prime examples of this convention. If your variable stores a constant value, such as static final int NUM_GEARS = 6, the convention changes slightly, capitalizing every letter and separating subsequent words with the underscore character. By convention, the underscore character is never used elsewhere.

Naming Method:

Although the method name can be any legal identifier, service code names limit method. By convention, method names in lower case should be running or multi-word name that starts with small running track with substantive degrees, etc., names of many words, the first letter of each other and make use of words.

Here are some examples:

run

runFast

getBackground

getFinalData

compareTo

setX

isEmpty

Overloading Methods

The programming language Java supports overloaded methods, and Java can distinguish between methods with different method signatures. This means that the methods of a class may have the same name, if different parameter lists (there are some conditions for this, which will be discussed in the course entitled "Interaction and heritage).

Suppose you have a class that can use calligraphy to draw different types of data (strings, integers, and so on) and contains a method to prepare any type of data. It is inconvenient to use a new name for each method, for example, string, drawInteger, drawFloat, and so on. The programming language Java, you can use the same name for all the training methods but pass a different argument list for each method. Thus, the elements of design class, declare four methods named draw, each with a different parameter list.

public class DataArtist {

...

public void draw(String s) {

...

}

public void draw(int i) {

...

}

public void draw(double f) {

...

}

public void draw(int i, double f) {

...

}

}

Overloaded methods are differentiated by the number and the type of the arguments passed into the method. In the code sample, draw(String s) and draw(int i) are distinct and unique methods because they require different argument types.

You cannot declare more than one method with the same name and the same number and type of arguments, because the compiler cannot tell them apart.