fabiochiu/medium-articles huggingface dataset:
Final keyword in Java
By: Shubham Arya
Tags: Java, Oops Concepts, Object Oriented, Oops Interview Questions, Final Keyword

Final keyword in Java can be used in multiple places and I have seen whole chapters dedicated to this particular topic.

But, I want to share a very brief but to-the-point understanding of the final keyword in this article.

If you are using final keyword for any member(local variable/instance variable/method) it means there is no way that you can modify the value of that particular variable(if method, then you can’t override that method) throughout your program.

Compiler throws an error if you try to update a final variable

If you are declaring a class as final, then, it means that no other class(in same or different package) can extend that class(final class), in other words the final class can never be subclassed, but, the final class can be used as the “Superclass reference”.

Superclass reference just means that it can be used polymorphycially

Third is the case which you are referring to. If any object reference variable is declared as final, then it means that the final reference variable can never ever in its entire life refer to a different object but the data within the object(the object your reference variable is referring to) can be modified.

Hope it clears some of the concepts.
Classes & Objects in Ruby
By: Kyle Le
Tags: Class, Ruby, Ruby on Rails, Object Oriented, Oop

Ruby is an awesome Object-Oriented programming language which allows us to use many of data types. Like integer, string, float, or boolean.

But not all things in the world can be represented by just a string or a number. A lot of things are much more complicated such as a book, a machine, a tree, or even a person. So this is one of the reasons why Ruby is cool, that we can create our own data types.

That means I can create my own data type which can represent a book or a computer. Literally anything I want, I can create my own data types. And it’s called Class. A Class is simply a data type that I can define. And Class in Ruby can be created with keyword class

So let’s say I want to create a person, and here is what a person looks like in my program:

So a person must have a name, age and gender. So this is like a blueprint or a template for a person. Now that I just told Ruby what a person is, let’s create a specific person in our program. And this is called object. An Object is simply an instance of a Class. So in this case I will create a person object:

So basically I just created a specific person in my program, and that person is based on a class name Person. And like I defined in that class, a person will have a name, age and gender. So now I can say that:

In this way I just set all the attributes for that person. And I literally mean it:

I just printed all the attributes of the person object that I created, like name or gender or age. And Classes can have methods beside attributes. So in this case, a person can have personal acts right ? So I will define a method called speak in the Person class:

Now I will create another person to test out this method:

As we can see, I just created a person who is Sasha and let her speak.

So in the end, we can create a class, create instances of that class called objects,and we can refer to them directly. And that’s how classes and objects work, they allow you to create your own data types in Ruby.

And one cool thing in Ruby is that almost everything in Ruby is a object, but we can talk about this in other articles ;)
Objects and its Internal Representation in Java Script
By: Vijay R.B.
Tags: JavaScript, Object Oriented, Script, Objects, Internal Representation

As usual we are familiar with the term Object as an real world entity in other programming languages but in Java Script it is termed as Standalone entity where every object has its own properties and type.

To get good understanding about Java Script Object, let see an example,

Consider a car which has its own properties such as color, design, weight, engine type etc Likewise Java Script Object has it’s own properties which defines its characteristics.

How a Java Script Object can be defined?

We can define the object in following ways they are

var myCar = new Object();

myCar.make = 'Ford';

myCar.model = 'Mustang';

myCar.year = 1969;

In above example the object mycar is created with the syntax

var myCar = new Object();

Here,

var - Variable declaration.

myCar- Object name.

new Object()- is the function to create object.

Here the properties of the object is given using (.)dot operator.

like myCar.make=”ford” ==> Here make is the property of object myCar.

Another way to create Object in Java Script is

var myCar = {

make: 'Ford',

model: 'Mustang',

year: 1969

};

It the same object a we created earlier, This is the syntax to create object in another way that is usually followed by us.

Here, As mentioned above var is declaration and myCar is object name,where the new Object() function is not necessary if we create using the above method.

OK now we know object is created,the properties and characteristics are defined.

But, how to access the e particular element of the object ?

It is accessed using (.)dot-operator, For eg., In above object if you want to display the make property of the object the below syntax is used.

myCar.make;

It will return as

Here the keys are[make,model,year]

Values are [ford,Mustang,1969]

Same method is used to access other values of the keys from the object.

You can also access the Keys and Values of the object by using the syntax

Object.keys(Objname)//Incase to access keys

Object.values(Objectname) //Incase to access values

Here is the practical example how it can be done by using previous object

Here the values returned from the functions are in the form of array.

These the basic ways to create and access Objects in the Java Script and its Internal representation.
Avoid accessing class attributes through an instance in python
By: Imran Ali
Tags: Object Oriented, Better Programming, Python

Let’s begin with the example

Let’s say we want all the shipping containers to start with serial number 1000. The __init__ method which is used to create an instance of this class tries to assign the instance attribute serial to the class attribute next_serial in line 7. This is ok but we have a problem in line 8 where I am trying to update the class attribute next_serial using the instance. Let’s see if this works in the terminal

That didn’t work. Both containers have the same serial number. But why? Let’s look at our class definition again

In line 8 we are trying to modify the class attribute next_serial using the instance but what ends up happening here instead is that we create a new instance attribute next_serial.

So instead lets work on our class definition and try to fix that

This time we are directly accessing the class attribute next_serial using the class name and not self. Let’s run the code again in terminal

There we have it. Works now!

Finally let’s clean up the code and make it more explicit where we meant to access the class attribute

Conclusion

While you can access the class attributes using the instance for read purposes, you cant modify them. To modify class attribute you need to access the attribute using class name. Also, accessing class attribute using the class name makes it more clear to the reader which attribute you meant to access so this helps in project maintenance. Not being careful of this pitfall could cause frustration when debugging failures.
C++ vs Rust — simple polymorphism comparison
By: Yacob Cohen-Arazi
Tags: Object Oriented, Rust, Software Engineering, Cpp, Software Development

Let’s start with the purpose of polymorphism: with dynamic, runtime polymorphism, we’re able to hold a pointer or reference to a type that is actually pointing to a more concrete, derived type. It’s the basic lesson that people learn when working with OO (Object Oriented) languages. For our example, we’ll use Animal as the base, top level type, along with more concrete types, like Cat and Dog.

Animal class type has a

Virtual default destructor. This is needed to deallocate the correct type when dealing with heap allocation. Although this is outside of the scope of this article, feel free to ask questions in the comments section. Virtual method/member function talk() . It is pure virtual, not implemented. The derived, concrete class(es) type(s) must implement it in order to create an instance. Here is how:

The above is simple: we create two new classes, Dog and Cat, use public inheritance from Animal, and implement the pure virtual function declared in the Animal base class, talk(). The final keyword defines that the class will be a leaf type. You cannot subclass from Dog/Cat.

Here is how we can use the class hierarchy demonstrated in “Modern C++”.

For this to compile, you will need to #include the following headers: <iostream>, <memory> and <vector>.

In the above main function, we created a vector of pointers to the Animal class type. We use unique_ptr<> to manage the heap allocation and deallocation. This is a C++11 feature. make_unique<>() is a helper function from C++14 that allocates such concrete type instances.

Finally, we create the loop (C++11 feature — range for loop) to iterate over Animal and invoke talk() on each instance. So long as each type implements the talk() interface (override virtual function of Animal base class), the type of the concrete instance is irrelevant.

Here is the output:
The Guide I Wish I Had for JavaScript Object Creation Patterns
By: Liz Fedak
Tags: Programming, JavaScript, Object Oriented, Oop

Object Factories With Mix-Ins

Using object factories with mix-ins is good for modeling objects that don’t have a clear “is-a” relationship. In the example below, we can create three distinct and unrelated types of objects — platypuses (aka platypi or platypodes), penguins, and humans — that share some behavior but are not in any way subclassable. Rather than duplicating code in methods for each object factory, the behavior is mixed-in using Object.assign , which copies all enumerable properties from a source object into a target object.

In the code, details , swim , and layEggs are objects with properties that all have function values. There are three functions for creating three different types of objects: createPlatypus , createPenguin , and createHuman . These three functions can be used to create new instances of these types of objects.

Taking a look at createPlatypus , we see the function takes a name parameter. In the function body, Object.assign is used to assign the enumerable properties from the details , swim , and layEggs objects into an empty object. After the properties from those three objects are copied into the new object, it uses the addDetails method, which was copied into createPlatypus from the details object when we used the Object.assign method, which copies in enumerable properties. Thus, it creates a new platypus object with a name property and the methods from the details , swim , and layEggs objects.

If you check the properties of objects instantiated from these functions, what do you think you’ll see?

> let platypus = createPlatypus("platypus");

> let penguin = createPenguin("penguin");

> let human = createHuman("human");

> human

{ displayDetails: [Function: displayDetails], swim: [Function: swim], name: 'human' }

> penguin

{ displayDetails: [Function: displayDetails], swim: [Function: swim], layEggs: [Function: layEggs], name: 'penguin' }

> platypus

{ displayDetails: [Function: displayDetails], swim: [Function: swim], layEggs: [Function: layEggs], name: 'platypus'}

If the use of the addDetails method was confusing there, here is another version where we set the details in the function itself. Note that within these functions, the execution context is going to be the global object, but we can use an empty object assigned to a variable to add some properties locally as shown on lines 22–25.
Short intro into classes in Ruby
By: Merdan Durdiyev
Tags: Oop Concepts, Class, Ruby, Object Oriented, Rubylearning

Welcome, dear friends, readers, and coders! This article will be dedicated to classes in the Ruby programming language.

OOP (Object Oriented Programming)

Before starting classes, let’s define what OOP is. In short, OOP, or Object Oriented Programming is a concept used in almost all programming languages that let us define anything in the digital world by making it resemble a real-world object. So, what does that mean?

As we all know, any object in the real-world has attributes and movements. Otherwise, the attributes of an object are its properties, and its movements are its actions or methods. This way, we can model any type of object in a digital world by providing it with real-world object features.

Let’s try to define a car:

Properties :

color

price

brand

model

manufacture date

and etc.

Methods:

start

stop

turn

accelerate

brake

and etc.

This way we defined a real-world object with its features and now we can model it in a digital world.
JS Study Note: 以 constructor 及 prototype 建立 instance object
By: Jackson Hsieh
Tags: Prototype, JavaScript, Object Oriented

inheritance in JavaScript

Object.getPrototypeOf(Object.prototype) === null; //true

此筆記是 MDN 內容之整理，以及一些補充:

create first constructor function:

首先要注意的點就是，property 最好都定義在 constructor 中，如果建立在 prototype 中，this 會指向 window object 而不是 constructor:

但如果是固定不變的 property 依然能定義在 prototype 中，而 method 定義在 prototype 是因為不想每次建立 instance 時，都建立一次 method，最好是透過 prototype chain 來接觸這些 method。first constructor 不用重新指派 prototype 跟 prototype 中的 constructor，因為 Person.prototype 的 prototype (__proto__ property) 是 Object.prototype，而 Person.prototype.constructor 已指向回 Person，這樣能讓我們透過 Person.prototype 來使用 Object 的 method。

2. create second constructor inheriting first constructor:

利用 Person.call() 繼承了 Person constructor ，在這邊也加上了 subject property，此 property 為 Teacher 有，但 Person 沒有的。

如果在 console 中檢查 Teacher.prototype 會發現其 constructor 為 Teacher，而 __proto__ property 則是 Object.prototype，為了要讓 Teacher 繼承 Person 的 method，要讓 Teacher.prototype 繼承 Person.prototype，而不是 Object.prototype (即 Teacher.prototype.__proto__ === Person.prototype):

Object.create(Person.prototype) 會以 Person.prototype 當作 prototype 來建立一個空 object，也可使用另一種寫法:

Teacher.prototype = new Person;

只要把 Teacher.prototype 指派為一個 Person 的 instance，其 __proto__ 即為 Person.prototype，但是此寫法會產生 enumerable: true 的 undefined properties，能出現在 for-in loop 。

但如果我們檢查 Teacher.prototype 會發現裡頭沒有了 constructor property，當你創造 new Teacher 時，instance.consturctor 會出現 Person constructor，因為會使用 Teacher.prototype.__proto__ (即 Person.prototype) 的 constructor，因此要在 Teacher.prototype 中創造一個新的 consturctor property 指回 Teahcer constructor:

也可:

Teacher.prototype.constructor = Teacher; //enumerable: true

這樣一來，instance.constructor 即為 Teacher.constructor。

3. create new methods for Teacher:

Teacher.prototype.methodName = function() {}; //enumerable: true

4. Trying the example out:
Difference and similarities of Object-Oriented PHP and Procedural PHP
Tags: Object Oriented, PHP, Procedural Programming

PHP

Maybe You have just finished your web design course. You already mastered HTML, CSS, and basic Javascript. You are good at creating some static pages. But what next, you want to be a full-stack web developer. You want a more functional website that is data-driven. It takes data input from users and functions with respect to that. If that is so, you have to learn a backend server language. Among all back-end languages, PHP is still the most popular one. Like other languages, PHP also has two branches. One is the old school, procedural PHP and the object-oriented PHP. Let’s have a bit of discussion between them.

Our goal is to create a website that functions dynamically between the database and the user interface. Both ways we can achieve our goal, but procedural and oop takes a different path to reach the goal.

Procedural PHP language takes a sequence of instructions and follows a step-by-step approach to solve a particular problem. Here, Each step is done in a structured way so that a computer can understand what to do. And these instructions are divided into tiny functions in procedural programming while it is split into objects in oop. By using classes and objects in oop it generates models based on the real-world scenario.

In OOP, you create a class and define some properties and methods to it. You might not feel comfortable with those terms, properties, and methods. But if you know the POP, you know about variables and functions. In a way, they are the same thing. You declare a variable and create a function to solve a certain task. In OOP, you are doing the same thing but these variables and functions are wrapped in a class. This is called encapsulation, which is the main advantage of oop. A class encapsulated and stored for solving similar problems. Next, you just need to create an object for the class and use that for your purpose. This is called instantiation.

There are 3 types of access methods in oop. These are public, private, and protected. Data hiding is possible due to abstraction in OOPs and therefore it is more reliable than POP. Most of the modern sites are based upon oop. OOP provides a clear modular structure for programs and is good for defining abstract data types. Actually, it allows us the benefit of maintaining and modifying existing code. So it is far better to stick with oop after finishing the basics of PHP.
CS371g Fall 2020 Week 13: Siddhesh Krishnan
By: Siddhesh Krishnan
Tags: Students, Object Oriented, College, Internships, Software Development

That’s me!

What did you do this past week?

This past week I worked on wrapping up the Life project. My partner and I were able to complete the HackerRank and the basic implementation and just have some of the basic things left for the project. In other worlds, I completed some assignments for my other classes as well.

What’s in your way?

There isn’t anything in my way right now! My partner and I have almost completed the Life lab. Given that this project is very similar to Darwin, it was not too hard to implement.

What will you do next week?

Next week, I will completely wrap up the Life project. I will work on solidifying my understanding of inheritance and other concepts in preparation for the next test which we will have. Also, given the fact that it is Thanksgiving, I will be sure to spend some time (safely) with family and friends!

If you read it, what did you think of What Happens to Us Does Not Happen to Most of You?

I did not get the opportunity to read this article. I will be sure to read it when I get the time!

What was your experience of inheritance? (this question will vary, week to week)

I have used inheritance in the past, mainly is CS 314, so I have had some experience with it in the past. However, it was very interesting to see how inheritance works in a C++ standpoint with inheriting from Abstract Classes as well as having Handler classes as well. It was also interesting to see how this would work with the Life project as well.

What made you happy this week?

This week, I was able to meet some of my friends who were on campus. Being from Austin, they were able to drive up to my house and surprise me. It was a pleasant surprise and really made me happy this week.

What’s your pick-of-the-week or tip-of-the-week?

My tip-of-the-week this week would be BinarySearch.io! This website is a good way to practice algorithms as well as work on your coding skills in a group setting with friends. Make sure to check it out!
Object-Oriented Programming in Python Part 1: Creating a Class
By: Ashley C
Tags: Programming, Computer Science, Oop Concepts, Object Oriented, Python

Here we have an example of a class that creates a Dog object. It might look intimidating being new or unfamiliar to OOP, so let’s break things down.

Class

An object is always created with the keyword class. A good convention for naming a class is using an uppercase letter for the name (in this case I picked Dog).

A class is essentially used when a category of objects have similar properties and attributes, but the objects differentiate from others by having different types of these properties and attributes.

In essence, a class is a blueprint for creating objects that have the exact behaviour, but different types of attributes and properties.

Object

Classes will have different instances, so when we say create an object of a class, we are referring to one instance of the class. Objects can perform different methods (the functions in a class), that are defined within the class.

Instance

The occurrence of an object within a class.

Self

Self is a parameter that references a current instance of the class and is used to access variables that belong within a class.

Note: self does not have to be named self and you could call it whatever you desire, although it is conventionally called self and it is best to keep it that way. Self is always the first parameter of any method in a class

__init__

__init__ is commonly referred to as a dunder (double underscore) or magic method. Classes will have their first method be an __init__ method (in some cases classes do not have an __init__ method, but that is not relevant right now). Essentially, this method will allow us to initialize the attributes of a class, and __init__ is always the first method that is called within a class.

Alright, so now that we understand a few key concepts, let’s take a walkthrough as to what is happening in this image.

Here, we are creating an object of a Dog. The attributes a dog has in this class are:

The dog has a name (a string). The dog has an age (a float, if the dog is less than a year, its age can be represented as a decimal). The dog has a breed (a string). The dog has a weight (an integer).

Under the declaration of __init__ you see:

Essentially what we are doing here is initializing the attributes of an object. This step is important since different dogs can have different names, ages, breeds and weights, which is why we must do self.attribute = attribute.

Whenever we are referencing a specific attribute of an object, we must always put self.attribute.
Ne ola ki bu Polymorphism(Çok Biçimlilik)?
By: Hakan Yavuz
Tags: Runtime Polymorphism, Polymorphism Nedir, Object Oriented, Compile Time Polymorphism, C Sharp Programming

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
C# 9.0 New Features
By: Abhinav Srivastava
Tags: Programming, Dotnet 5, Microsoft, Object Oriented, C Sharp Programming

C# 9.0 which is released along with .NET 5 brings many new features that are cool as well as will make our code experience a lot easier.

As there are many new features that come with C# 9.0, we will be mainly focussing on its top 4 new features. Remember .NET 5 is only compatible with Visual Studio 2019 (v16.8) as of writing this.

1. Init only Setters

Let's understand this with the help of an example.

Define a class Student with parameters:-

RollNo Name Age

All these parameters can only be initialized once. So let’s see how we were doing this earlier.

We cannot set the value of RollNo again as it consists of no setter and therefore can only be set using the constructor.

However, this constructor is basically an extra boilerplate code that we have to define in order to reach this functionality.

Now let’s do this using C# 9.0 new feature Init.

Now ‘init’ will let the property initialized only once during the program.

As we can see once the Student class is initialized its properties cannot be changed as they have “init” inside them.

2. Records

Let’s understand this with the same example of Student class. Before C# 9.0 we were writing this it like.

Now ‘record’ provides us more syntactical sugar. So starting from C# 9.0 we can write this

As we can see, that almost all the extra boilerplate code such as initializing constructor, defining getter with their properties are not required.

Its cool, Right !!!

By default, all the record properties are init only.

Let’s see how we can call this in our Main method

As the name property has already been initialized, we cannot set it again.

3. Top level Statements

For those programmers who love python and javascript as they almost require no boilerplate code, Top Level statements are for those and also for those who are lazy and think that even writing any unnecessary code is Muda (useless).

This is how we were writing a “Hello World” program before C# 9.0

Now let’s see the magic of C# 9.0

If you think its a bluff, no it is not. This one line of code is equivalent to the ‘Hello World’ program mentioned above.

It provides a script like experience and makes it easier for programmers to switch from languages like python and javascript to C#

Thanks, for reading this article Adios
Object-Oriented Design Principles
By: Prasad Jayakumar
Tags: Java, Design, JavaScript, Object Oriented, Beginner

Photo by Patrick Fore on Unsplash

Object-Oriented Design (OOD)

Every application is a collection of code; the code’s arrangement is the design. Design is thus an art, the art of arranging code

Object-oriented applications are made up of objects and the messages that pass between them

Class provides the blueprint for the construction of similar objects. A class defines methods (definitions of behavior) and attributes (definition of variables)

🙇 Practical Object-Oriented Design in Ruby by Sandi Metz

The purpose of the design is to allow you to design later and its primary goal is to reduce the cost of change

Practical design does not anticipate what will happen to your application

it merely accepts that something will happen and that, in the present, you cannot know what.

it does not guess the future, it preserves your options for accommodating the future

it doesn’t choose; it leave you room to move

How design fails?

The first way design fails is due to lack of it — Undesigned applications are easy to write but gradually become impossible to change

Programmers are aware of object-oriented design techniques but do not yet understand how to apply them — programmers fall into the trap of overdesign

Finally, object-oriented software fails when the act of design is separated from the act of programming

Object-Oriented Design Principles — S.O.L.I.D

S ingle Responsibility Principle — There should never be more than one reason for a class to change

ingle Responsibility Principle — There should never be more than one reason for a class to change Open Closed Principle — Software entities (classes, modules, functions etc.) should be open for extension but closed for modification

💡There are many ways to extend a class — inheritance vs composition

L iskov Substitution Principle — Functions that use … references to base classes must be able to use objects of derived classes without knowing it

iskov Substitution Principle — Functions that use … references to base classes must be able to use objects of derived classes without knowing it Interface Segregation Principle — Clients should not be forced to depend upon interfaces that they do not use.

💡Many client-specific interfaces are better than one general-purpose interface

Dependency Inversion Principle —

A. High level modules should not depend upon low level modules. Both should depend upon abstractions

B. Abstractions should not depend upon details. Details should depend upon abstractions

For detailed explanation and Java code samples, please refer to Pablo’s SOLID Software Development (PDF). Content compilation in the eBook is awesome 😆
How I found Python nested decorators, in my kitchen
By: Abhijeet Rai
Tags: Programming, Object Oriented, Design Patterns, Python3, Python

The concepts of object oriented programming are evident everywhere. And decorators are no exception.

Speaking about decorators in Python programming language, they are used to add extra features(tasks) to functions. Without changing the original code of function.

Let us suppose, I already have a function called ‘cook_chicken()’, which tells me to cook some chicken.

def cook_chicken():

print('Cook Chicken')

But now, I want to perform(implement) “two additional tasks”. Firstly, I want to cook chicken in tandoori and secondly garnish, chicken cooked in tandoori, with corriander (leaves).

Photo by Tuân Nguyễn Minh on Unsplash

So, now do I wedge(force) the code of “two additional tasks” (cooking chicken in tandoori and garnishing it with corriander), in function ‘cook_chicken()’ itself. The answer is ‘No’.

Because, what if I want to write another function(which tells me to cook something else) and that another function involves these “two additional tasks”(cooking something in tandoori and garnishing cooked dish with corriander) again. I will have to write code of “two additional tasks” in that another function as well, again. This static unflexible approach leads to repetition of code and abuse of resources, illustrating flawed design practice.

Apart from that, what if function ‘cook_chicken()’ is legacy code(or part of legacy code), then you would not want to disturb the code of function ‘cook_chicken()’. Because even if function ‘cook_chicken()’ may look negligible in size, here. Legacy code of actual software projects revolves around thousands of lines. And disturbing legacy code is a foolish move and open invitation to bugs.

Also a design principle(in programming) states, “A class or function should be open for extension, but not for modification”.

Which means if you want to add a new feature(or task for that matter) to a function (or class). You should not modify the old legacy code, which has been around already, you should extend the legacy code dynamically.

So there has to be some way to implement the code of “two additional tasks”(cooking chicken in tandoori and garnishing it with corriander), in some dynamic and flexible way.

That’s where Python decorators would come in play. Two (nested) decorators would be required, one would implement task of cooking in tandoori and another would help garnishing, dishes(cooked items) with corriander (leaves).

Decorator prepare_indigridents() will garnish chicken with corriander. Decorator cooking_on_tandoori() will help chicken to be cooked on tandoori.
Object-Oriented Programming #1: Inheritance & Abstract
By: Andre Saftari
Tags: Java, Object Oriented, Programming

andresaftari/PBO-Java

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build…
[Programming!] Let’s easily talk about…Class and Constructor!
By: 陳芃諭 Bonnie Chen
Tags: Programming, Program, Object Oriented, Programming Languages, Csharp

To the programmer, “class” is not unfamiliar, right? 👌

In the previous article, I had written very simple concept of “class” and “object”.

The link is below 👇

https://medium.com/ponpon841028/programming-class-object-new-c7924f712478?sk=b8c06c7a948349134bca611176f02e77

In this article, I would describe about “class” in detail.
Decorating Class Method
By: Vignesh Jeyaraman
Tags: Object Oriented, Class, Python3, Decorators

Source:- Towards Data science | Google

Hello Guys,

Came across an interview question about how will you decorate all methods of the class without decorating each method separately.

I was not able to answer that then I started searching for the answer and I finally found how to do that. It is a bit complex compare to normal decorators.

For decorating all of the methods of the class we have to override class special method __getattribute__ which gets called every time we call an attribute or method on the class object and this is the reason that this has performance concern and slows our code a bit.

I have written the below code to explain how to do this. This might be back-breaking at the start but please sure you read the comments carefully and try to understand what the below code is doing.

It will print the below output:

I am decorating

I am fun

Let me know in the comments if you have any questions or any difficulty in understanding what is going on here.

Stay safe and keep learning!!
Coding Side Project #1 — Jumpers for Goalposts
By: Chris Whitehouse
Tags: Game Development, Football Manager, Ruby, Object Oriented, Makersacademy

Photo by Austrian National Library on Unsplash

Why: As a teenager I used to love playing Football Manager 97 (yes, 97…). It was an addictive game; having many of the attributes of the hook model:

Action; play a game Variable reward; result of the game Investment; league position, and building a squad Trigger; automatically loop to next game, to complete a season

But I particularly enjoyed the building a squad. Finding the best young players, to bring into the team.

On my Makers pre-course, I recently learnt about object oriented programming, and test driven development using Ruby’s Rspec library.

In bed, this morning, I was pondering if it would be possible to build a really simplistic version of Football manager to test my new found OOD, and TDD learnings.

How: To be built in ruby, using recently learnt OOD, and TDD methods. Using the command line as a user interface. A football manager game has a variety of objects that interact: a game; a team, a squad, players.

What: Jumpers for Goalposts; the park football simulation game.

Two teams of five players. With attackers and defenders. Play a single game.

Who: i’m the customer of this project. But other nostalgic 30 something nerds, might also be intrigued.

Where: To be published to github: https://github.com/chriswhitehouse/jumpers-for-goalposts

When: Try and complete an MVP this afternoon.
[Programming!] Xml <-> Object, Serialization and Deserialization (Part 2)
By: 陳芃諭 Bonnie Chen
Tags: Programming, Object Oriented, C Sharp Programming, Xml, Software Development

Deserialization is an opposite process to Serialization. Which means converting the xml file to the object!

Take the xml file below for example.

There is an ListBook object containing three Book objects. Also, these three objects have Name, Price and Author properties.

Besides, we can see the other information about xml file, like xml version number, encoding declaration and namespace.

However, how do we deserialize this xml file to object?

1. Setting the elements/class

On the purpose of mapping the elements to objects correctly, we should create classes that are consistent with the roots and elements in the xml file. Which can be seen below.

If you had seen the previous article, you will find that you are familiar with it 😆. Because deserialize is opposite to serialize, they should be keep the same class structure. To make deserialize know what class structure the object should be.

2. Reading the XML file and Deserialize it

Then, loading the Xml file and retrieve the InnerXml from xmlDocument. The InnerXml is the string type which can let me do StringReader later.

Next, call to the XMLToObject function, which is told to XmlSerializer that the xml file should be mapped to which object type. And, do the deserialize!

After receiving the object from the XMLToObject function, have to unboxing the datatype to the ListBook.

And, finished deserialize!

3. Check out the objects !

Finally, through printing on the console, let’s see what is the content in the xml_listBook object! And, does it make sense?

It’s seem… CORRECT! 😆 😆

So it is about deserialization!
Creating a class that can only be initiated once — Singleton design pattern
By: Vikesh Mittal
Tags: Singleton Design Pattern, JavaScript, Oojs, Object Oriented, Typescript

Creating a class that can only be initiated once — Singleton design pattern Vikesh Mittal ·Nov 12, 2020

How to create a class whose only one instance can exist?

We usually create instance of a class using new keyword. Each usage of new will create one instance of the class. Now we know that whenever we use new keyword, it calls the constructor of the class. What if we make the constructor private? But then how would we create even the first instance of the class.

Solution is to create a static method inside the class that will call private constructor and keep a tab on the instance of the class.

You can verify this by adding a public variable in the class and changing its value. See full code below:
Class Inheritance
By: Joseph Napoleon Ochoa
Tags: Launch School, Oop Concepts, Ruby, Object Oriented, Class Inheritance

Class Inheritance/Single Inheritance:

Class inheritance/Single Inheritance is when a subclass gains access to the behaviors and attributes from the superclass. We use class inheritance when we the relationship between the subclass and superclass are tied together.

Let’s take a look at this example:
Polymorphism: Class Inheritance, Mixins/Interface Inheritance, & Duck Typing.
By: Joseph Napoleon Ochoa
Tags: Launch School, Oop Concepts, Ruby, Object Oriented, Polymorphism

In this article I will explain what Polymorphism is and try to keep it to the point. I will be using the following structure to explain everything. First show an example, then talk about my example and how it relates to polymorphsim.

Polymorphism:

Polymorphsim is the ability that different objects instantiated from different classes can respond to the same method call in a different way. There are 3 ways to achieve this, through class inheritance/single inheritance, mixins/interface inheritance, and duck typing.

Class Inheritance/ Single Inheritance Polymorphsim:

As you can see from the example above, we have defined 3 class definitions from lines 1–14. On lines 16–17, we instantiated 2 objects from 2 different classes. However, you can see that on lines 19–20 we are calling the same method on two different objects that are instantiated from different classes. The fact that we can call that same method call on both objects is Polymorphism. With class inheritance polymorphsim siegfried is using the attack method that was inherited from Character , but athos is using another method with the same name, but with different implementation.

Mixins/Interface inheritance Polymorphism:

On line 24–26, a new class was defined, and on line 30, a new object was instantiated from the new class to further demonstrate our example. On lines 35–36 we called the method range on both objects, but this time the methods were inherited from the module LongRange . We did this by using include and including in the LongRange module. This then gained access to the behaviors from LongRange . Since the relationship is more of a has a relationship, this makes sense to use a module and also because we want multiple inheritance. Since we now know what mixins are and how subclasses gained their behaviors, we can now see this in the context of polymorphism. On line 35–36 we called the method range on both objects that are from different classes. Since the methods are accessed from a module and have different implementations, then this is an example of Polymorphism through mixins/interface inheritance.

Duck Typing:
[Programming!] Xml <-> Object, Serialization and Deserialization (Part 1)
By: 陳芃諭 Bonnie Chen
Tags: Programming, Object Oriented, C Sharp Programming, Xml, Software Development

Serialization is a process that converting an object to XML file. Through this procedure, we can save the state of an object, in case we want to recreate the object. Of course, we also can deserialize XML file to an object 👍.

So… How to serialize an object to XML?

1. Setting the elements and creating the objects

First of all, supposed that an object structure is a list, which contains three objects. These three objects in the list are the Book object. Book object has Name, Price, Author properties. Which can be seen in the below screenshot.

The elements of Name, Price and author are the Book’s child nodes, and the Book is ListBook’s child node.

Also, we instantiate Book and populate the property value in these objects. Last, adding these three book objects into the Books which is ListBook property.

2. Object serialize to XML

After setting the elements and creating the objects, we just remain the one process to finish converting the object to XML.

In the screenshots below, we can see I call non-return generic method ObjectToXML with two parameters. Give it an object and the xml file saving path, and we can make XmlSerializer know that how objects are encoded into XML, and also Serialize the object to XML file.

And…. It’s done! 😆

P.S: Ahh.. I want to supplement something. Generic method is an really useful method that can be declared any datatype, thus it has reusability and even removes the boxing or un-boxing situation. Also, Generic method could be related to Delegate concept, or IoC design principle.

Perhaps I would write more about it in the future articles 🙌 🔥 👌

3. Check out the XML file! 😎

Finally, let’s check out the file in the folder!

We can see that IT IS DONE that converting the object to XML file!

Overall, this is just about how to convert an object to the XML file. In the next article, I would describe how to convert the XML file to an object, also known as deserialize.

If you like this article, welcome to give me the clap. Also, it is nice that if any questions or thinking want to share, comment or email to me! 😁 🔥 👍
What are Wrapper Classes in Java?
By: Veysel Aksin
Tags: Java, Primitive Data Types, Wrapper Class, Object Oriented, Oop

Hello everyone, today we will talk about wrapper classes in java.

Actually must be known firstly primitive type.

Primitive type: In computer science, a primitive is a fundamental data type that cannot be broken down into a more simple data type. For example ‘int’ is a primitive type.

The size of primitive data types is fixed, there cannot be assign null value and if no value is assigned the value become zero.

Below you can see the minimum, maximum and size of memory values ​​of the primitive types.

Now that we have learned the primitive types, we could learn to wrapper classes.

Primitive types are instance variables but wrapper classes are object variables and we are using to when we want to create an object type variable.

Below you can see the minimum, maximum and size of memory values ​​of the wrapper classes.

I told as best I can about wrapper classes. Thank you for reading this article. Follow if you like my articles, see you in next article, take care.
用C#學習物件導向設計：簡介. 從以前就蠻想好好的來整理下物件導向設計的相關概念，在寫完資料結構與演算法的系列文…
Tags: Object Oriented, C Sharp Programming, Solid

什麼是物件導向

先來看看維基百科的介紹：

物件導向程式設計（英語：Object-oriented programming，縮寫：OOP）是種具有物件概念的程式程式設計典範，同時也是一種程式開發的抽象方針。它可能包含資料、屬性、程式碼與方法。物件則指的是類別的實例。在物件導向程式程式設計裡，電腦程式會被設計成彼此相關的物件。

根據上面的描述得知，我們可以用類別（Class）來定義一個事物的抽象特點，包含了事物的屬性( Field )以及方法( Method )，像是將類別想像成一個手機藍圖，裡面包含了廠牌名稱，規格及功能等資訊；而物件( Object )即是類別的實體化，可當成根據藍圖實體化生產後的手機。而一個程式中包含著各種獨立而又互相呼叫的物件，即是物件導向程式設計。

為何要學習物件導向

談到為何要學習物件導向，首先要了解一下程式碼的好壞。首先，一段程式要能動的起來，說明這個程式是可以滿足客戶需求的；再來是這個程式應該要能夠被切割，即大的任務能分解成多個小任務，方便在各種情況下進行測試以確保程式能順利運行(單元/集成測試)；然後是這個程式應該是要足夠穩定的，即不會因為更新、添加新功能，就出現錯誤(改 A 壞 B)；程式也需具備能「重覆利用」的特性，可將重覆執行的程式碼獨立出來，增加維護性及開發效率；最後是可讀性與可擴展性，前者是讓人能輕鬆的了解程式的功能，後者則是容易添加新的功能。

看到這邊大家可能都會有種「要馬兒好，又要馬兒不吃草」的感覺，如此完美、顧及每個面向的程式真的有可能寫的出來嗎？個人認為是有些困難的，比較能做到的是寫出「能配合專案需求」且「較好維護」的程式碼，這時對專案的了解程度就很重要了，也能看出一個工程師的功力所在。而透過熟悉物件導向的特性與設計原則，能讓我們在設計程式時，寫出較佳的程式碼。

物件導向的四個重要特性

物件導向程式有四個重要特性如下：

抽象( Abstraction ) 封裝( Encapsulation ) 繼承( Inheritance ) 多型( Polymorphism )

抽象即為將真實的需求轉換成物件導向中的類別，可包含狀態(屬性)與行為(方法)。以前面提及的手機藍圖作例子，我們可將每支手機共有的特性如裝置、公司 、電量及功能等，抽離出來放在類別中：

public class CellPhone

{

public string model { get; set; }

public string company { get; set; }

public int battery { get; set; }

public void Function(){}

}

封裝可以隱藏/保護內部實作的細節，並可以對屬性或方法設定存取層級( public, private, protected )。像是對剛才的 CellPhone 類別加入一個不對外公開、且只能在該 class 內部做調用的方法：

public class CellPhone

{

public string model { get; set; }

public string company { get; set; }

public int battery { get; set; }

public void Function(){}

private void ProtectFunction() { } //只能在內部調用該方法

}

繼承是建立新類別以重複使用、擴充和修改其他類別中定 義的行為。像是可以將剛剛 CellPhone 中的方法改成 virtual 方式：

public class CellPhone

{

public string model { get; set; }

public string company { get; set; }

public int battery { get; set; }

public virtual void Function()

{

Console.WriteLine("origin function");

}

}

然後再新建一個類別，在建構式中呼叫基底類別並使用 override 複寫剛剛的 virtual 方法：

public class NewCellPhone : CellPhone

{

public NewCellPhone() : base() //呼叫基底類別

{

model = "iphone";

company = "Apple";

battery = 3000;

}

public override void Function() //複寫方法

{

Console.WriteLine("override function");

}

}

多型則說明了在相同的介面下，可以用不同的型別來實現，像是剛剛基底類別宣告的 virtual 及後面複寫的 override 方法也是多型的一種。事實上在 C# 中，所有類型都是多型類型，因為所有的類型(包含使用者定義的類型)都是繼承自 Object。

物件導向設計原則( SOLID )

根據上面的四項重要特性，發展出了五項物件導向的設計原則，除了可以用此衡量程式碼的好壞( code smell)外，也有著降低程式的複雜度、較佳的程式可讀性，高內聚低耦合，容易維護等好處。這五項設計原則就是這個系列文的目錄：

單一責任原則 SRP ( Single Responsibility Principle ) 開放封閉原則 OCP (Open Closed Principle) 里氏替換原則 LSP ( Liskov Substitution Principle ) 介面隔離原則 ISP ( Interface Segregation Principle ) 相依反轉原則 DIP( Dependency Inversion Principle )

接下來會一篇篇的講解各原則的特性並使用 C# 進行實作，希望大家都能有所收穫。
Your guide for Inheritance & Polymorphism concepts!
By: Dasari Swaroop Kumar
Tags: Java, Inheritance, Object Oriented, Polymorphism, Oops

This is my take on explaining Inheritance and Polymorphism concepts to everyone in the simplest way possible with real-time examples.

Inheritance:

Let’s take an example to understand what inheritance actually is, Everyone knows that they inherit their parent's property and your’s to your children and this process continues, right?

what do you inherit from your parents? their properties like land, gold, wealth that they have created for us, etc., Some parents, on the other hand, want their children to earn their own money and live out of it, they teach their children the value of money. Assume that their property doesn’t go to their children and it goes to charity.

Now let me connect the above story with the java inheritance concept.

Assume that I have a class Parent with 2 fields, ‘land’ and ‘wealth’ and class Child is extending the class Parent. From the above example, assume that this is the first type of parent. So, Child will inherit the properties of the Parent i.e., Child will have access to ‘gold’ and ‘wealth’ properties of Parent class.

The second type of parent, on other hand, doesn’t give access to the property he has to the Child class. This can be achieved by using the ‘private’ modifier in java. using this modifier prevents the Child class to inherit those fields from the Parent class.

For the rest of the part, let’s take the first type of parent as Parent class.

Assume that the Parent class has two methods, m1() and m2(). Hence Child class also has access to those methods. Even Child class can have it’s own methods and fields too. One of the main advantages of this concept is that Child class need not have m1() and m2() methods in it again, which adds up to the feature of re-usability of code. (eliminates redundancy of code)

Code for the above concept will look something like this,
Javascript Object Property, undefined vs null
Tags: JavaScript, Object Oriented, Null, Undefined

Undefined vs Null

When creating a Javascript object, I always hesitate whether I should leave a property undefined which have no value or initialize it to null .

Let me show you an example of typescript. there is an interface about the object.

interface Section {

title: string

contents: Array<unknown>

children: Section | null

}

Anyone can set children ‘s type as Section | undefined but i chose null . That’s because null is a value, so I can leave it defined. In Javascript, undefined means nothing, that is uninitialized. undefined can break the principle of OOP because It can be treated as other class object normally unless Inheritance is used.