E-commerce Hero Section UI UX Design

E-commerce Hero Section UI UX Design – Ecommerce Website Design – HTML CSS Only

This thing is called Polymorphism which means the ability to take multiple forms. We will now see how to design a class using this property. And polymorphic object is an object that can take more than one form.

Now I want to create a class DataProcessor. This data processor performs various data processing tasks and takes the help of SummationService to perform the task. The class could be:

I have only shown the use of SummationService, the data processor may do much more. Now let’s run this code and test it:

E-commerce Hero Section UI UX Design – Ecommerce Website Design – HTML CSS Only

Now the fun part is, we can create the DataProcessor in two ways, using the new SimpleSum() parameter and using the new UniqueSum() parameter. Because both SimpleSum and UniqueSum classes actually implement the SummationService interface. The DataProcessor doesn’t need to know which implementation is being used, it just knows that it has an interface called addNew and findSum that can be used to add new data and find the sum.

Now whoever needs it will use that implementation and summationService will use its polymorphic power to take that form. The power of polymorphism is to have different forms as needed.

Polymorphism is not only applicable to interfaces, we will learn more about it later.

Let’s see a real usage to understand more clearly. When we need to use lists in Java, we usually write:

What is actually happening here? List is an interface defined in the official Java library, and ArrayList is their own implementation. Now suppose your ArrayList is not working, Linked List is needed because deleting elements in array takes more time, then you can write:

LinkedList is actually another implementation of the List interface. list is a polymorphic object, ArrayList can be assigned to it, LinkedList can also be assigned. If you create a method that takes a List type as a parameter, you can pass any object that implements List to that method, try it out.

The Boeing 737-Max Tragedy

You may have seen two of Boeing’s 737-Max series planes crash a few days ago. There was a problem with the software design of this plane. Boeing has changed the implementation of some of the plane’s features, but they haven’t made any updates to their interfaces. They thought that keeping the interface the same would not require retraining of pilots.

What happened next was that the plane began to drift from the sky to the ground due to a failure of the implementation of the autopilot feature, the pilots had no idea what was happening, they had no interface to take control. Hundreds of people died on two planes due to this mistake, and all airlines have now grounded the plane. What better example of how deadly a software bug can be?

So today we learned:

  What is the interface?

  What is Abstract Method?

  What is polymorphism?

  How to achieve Polymorphism using Interface?

Your task will be to search each keyword in Google and learn the details. Oracle official website has explained everything easily, you can read them.

In the next episode, we will know what Inheritance is and its use. So far today, if you have any problem to understand any part, you can tell in the comment section.

Tail-call recursion optimization

When using recursion, it is often seen that if the recursion depth is too high, it runs out of memory and crashes the code. Today we will learn an optimization technique that can sometimes greatly reduce the memory usage of recursion.

First you need to know what is tail call. Simply put, a tail-call is the last line of a function. That is, tail-call is the function after which there is no more work to do. For example look at your function:

It is a function to extract factorials. In this function, after return ans the function has no further work, so this is the tail-call.

Why use mod? Because we have very large n

will use but we don’t want integer overflow.

Now we will write this function using recursion:

A recursive function is called tail-recursion if the recursive call is tied to the last operation of the function. The last function of the above function is to return the value of n∗fact(n−1). So the last task is to call fact(n–1) recursively? If you understand how recursion works, then you understand by now that this is not the end task! The function will first recursively retrieve the value of fact(n−1), then multiply it by n. We can write as follows:

Same function, just broke the last line a bit. From here it is understood that this function is not tail-recursion, we are not calling the recursive function in the last line, but we are doing the calculation by calling the recursive function in the previous line and using it in the last line.

E-commerce Hero Section UI UX Design – Ecommerce Website Design – HTML CSS Only

Now you use this function fact(1000000)

Try printing its value (I’m assuming you’re not changing any settings to increase memory). when i fact(1000000)

I ran it, immediately the program crashed and showed a segmentation fault. That means the program used too much memory and crashed. You may ask, I haven’t used any arrays, how come this code consumes so much memory?

Each function runs in one memory space. When you recursively call the same function, run the function again using the new parameters in the same memory space and return using the old parameters to finish the rest of the work.

take you fact(3)

want to find out Going to line 8, the code will call the same function using n=2. That means the function will now run using the new parameter n=2 in the same memory space. Then at some point come back and do the rest of the calculation in line 9 using the old parameters. Since the same memory space is being used, how does the process know when it returns that n

What was the value before?

A stack is used internally to detect this. Every time you make a recursive call, the old parameters are saved on the stack.

When calling fact(2) from fact(3) n=3 is being saved on the stack. Similarly n=1 when calling n=2

K is being saved on the stack. Because of this saving, the parameters of the previous function call on the stack can be easily found when returning from the end of the recursive call. (You can read my article about stack for details.

when you fact(n)

   When you call, you have to save n entries in the stack like this. There is a limit to how much memory recursion can use in C++. n

When its value is too large, the memory usage limit is exceeded, and the code crashes.

E-commerce Hero Section UI UX Design – Ecommerce Website Design – HTML CSS Only

Before Download

You must Join our Facebook Group and Subscribe YouTube Channel

All Links in Below:

Join Our FreeWebsiteCreate Facebook Group to get an instant update for projects, templates, design resources, and solutions.

Join Our YouTube Channel & Subscribe with Bell Icon for New Video:

Join Our Official Facebook Page For the Latest updates All Code Projects are Free:

Visit our service page to get premium services.

Free Website Create – HTML CSS, PHP, JavaScript Programming Projects For Free

Follow Us

Thank You,

Stay with FreeWebsiteCreate.net

Share the post if necessary.

Before Download

You must Join our Facebook Group and Subscribe YouTube Channel

FreeWebsiteCreate.net tries to provide HTML, CSS, SCSS, JavaScript, React, Android Studio, Java, PHP, Laravel, Python, Django, C#(C Sharp), and ASP.net-related projects 100% free. We try to make learning easier. Free Website Create always tries to give free projects to new learners. Free projects and source code will help to learn quickly.

They can save time and learn more. In this post, we share a free portfolio project website code with HTML and CSS. This free code portfolio contains a single landing page with a responsive design. In this post, we get a free best carpenter and craftsman service website designed by FreeWebsiteCreate with HTML, CSS, Bootstrap, and JavaScript.

To get a free website project code,

Keep bookmarking our website, Save categories links, Follow Social Media, Follow the youtube channel Join Facebook groups.

Stay with FreeWebsiteCreate.net

Share the post if necessary.

Leave a Comment