Why Multiple Inheritance is discouraged?
Dec27

Why Multiple Inheritance is discouraged?

Welcome to CodeSpread! Hi Guys, This is Sathish Again,Today we will discuss why most of the higher languages eliminates Multiple Inheritance? Most of you guys already know that multiple inheritance is not available for development but what you might not know is the reason as why it is not possible. First of all,we will revisit few basics of inheritance. What is Inheritance? Wikipedia says “In object-oriented programming (OOP), 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 simple words, Inheritance forces reusability where a class reuses the functionality of another class by inheriting all its traits.We can take an example to understand more: In real life, We inherit some of our behavior from our parents,so we can deduce our parents as Base class,and ourselves as Derived class. What are the types of Inheritance? Single Level Inheritance: It is the basic type of Inheritance where child class B inherits/extends the behavior of a base class A. For ex: We can have a child class like TV which extends base class like Electronics. Multi Level Inheritance: Here, Single inheritance is captured at different levels and called as multi-level inheritance. We have a derived class C which extends class B, which is a child class of base class A. For ex: Can we say Ipad extends Laptop and Laptop extends Desktop? Multiple Inheritance: The concept of multiple inheritance is a derived class C extends more than one base class like class A and Class B. Multiple inheritance is not supported by many languages and can be achieved by using interfaces. For ex: Child extends behavior of Father and Mother. Now we will move to our basic question, Consider the c++ program mentioned below , where I have created 3 classes,Two of them are base class and third one is the derived class, Base1 and Base2 are Base classes Derive is the Derived class /*Program about multiple inheritance */ class Base1 { public : void Display() { cout<<"We are in Base class1 " ; } } ; class Base2 { public : void Display() { cout<<"We are in Base class2 " ; } } ; class Derive :public Base1,public Base2 { } ; If we focus on Base1 and Base2, then it is clearly visible that, Base1 class has a method called Display Base2 class also has a method called Display, We extend these base classes with our derived class. Let’s move forward and create an instance of derived class, int main () { Derive d; d.Display(); return 0 ; } When we call the...

Read More
Code Quality : Myth or Reality
Dec18

Code Quality : Myth or Reality

What is Quality? Generic definition of Quality “The standard of something as measured against other things of a similar kind; the degree of excellence of something” . So what i can add here is that quality can be measured only by comparing an item with someone of the same origin. It’s an iterative process which keeps on evolving so as to achieve a better of its own kind. Phew! Complicated? Really, There can not be a definite definition to quality and we can only relate it to the consumer’s satisfaction like if a consumer is satisfied, product was of good quality and if a customer is unhappy, product was of low quality. User satisfaction is the only measurement tool to assess quality. What is Code Quality? What we have defined above applies to our code. Till the time, client is not satisfied, our work is not over. But We have to put down a limit to this iterative process and find out the minimum guidelines required to achieve code quality. It is not possible to create the best code but an attempt can be made to achieve a better code by following few guidelines. Code Quality is a myth, if only the best code is available and a reality, if an option of better code is available. What is the current scenario? I wonder why people are so ignorant of code quality especially in the services sector where the stress is given to project completion and time lines. It works for a shorter period but when the client wants to do some modification or up gradation to their software and task is given to new developers or even existing developers, they are not able to perform the desired modifications. Where is the Gap? Gap is the poor quality of the code. Once we start our project, we seldom think of the quality, as our main focus is on to complete the project and clear all the necessary scans and reports. One more factor is foresight like we fail to visualize all the problems which might crop up in the software development life cycle, they might be complex, too time consuming, requires more effort or which are not easy to fix. We take the easy route to solve these problems and compromise the code quality. We are going to take help from MSDN and other resources to make code quality a reality. Steps to achieve Code Quality. At each stage of Software Development Life Cycle, there is a possibility of improving code quality Requirements: Bore your clients : This is the first suggestion, try and gather all the requirements from...

Read More

Asp.Net: More about Cookies

We have seen, how our cookies looks in our last article Cookies Part 1. In this article, we will talk about their properties,limitations and technical part. Properties and Limitations Cookies are associated with website and not single pages. Cookie is stored in our system as Text File. They are stored in plain text format i.e. no encryption. Their size on disk is limited to 4096 bytes. so only identifiers and ids are stored, big chunks of data are avoided. Browsers puts a limitation on the number of cookies stored. In case of more than the quota, old cookies are discarded. Nowadays, It is mandatory for websites to tell the user whether they will allow cookies to be stored so It depends on the user to allow or reject the cookie Even we can change our browser settings to allow or reject cookies. Go to your chrome settings->privacy->content settings Here, you can set your settings, if you want to see your cookies, click on ‘All cookies and site data’. We will move to technical part of cookies. We have two objects, HttpResponse and HttpRequest in our application life cycle which handles the use of cookies. For writing information to a cookie, we would require HttpRespone object. This object contains a collection of cookies where we just have to add our cookie. First of all, we will try to create a cookie and store some information. Write a Cookie As always, we require necessary classes to begin with and for that we require a Namespace.Here, we have System.Web, which will expose necessary classes. System.Web Now, We will use HttpCookie class to create our cookie HttpCookie ShoppingCart = new HttpCookie("ShoppingCart"); ShoppingCart.Value = ItemTextBox.Text; ShoppingCart.Expires = DateTime.Now.AddHours(1); Response.Cookies.Add(ShoppingCart); Earlier, we talked about HttpResponse but here we are using Response object. why? Both are same, HttpResponse is available to us in the form Response property of our Page so we are directly using Response object. Though we have other ways also to create cookies but this is the descriptive way to understand each step. As Response.Cookies is a collection, we can add more than one cookie to the collection by creating multiple cookies in similar fashion. Read a Cookie To read a cookie, we have HttpRequest object and this is also available in the form of Request property of our page. Lets use it and read the cookie. We just have to remember the name of our cookie and dig it out from the cookies collection of Request object. string shoppingcart=Request.Cookies[“ShoppingCart”].Value; OfCourse, Check for Null Value of shoppingcart before using it in your application else you might receive a beautiful error message. We have...

Read More

Asp.Net: Hidden Truth of Cookies

I know there are several articles on cookies as what are they? and how can they be created? but i always wanted to know more about them. My questions were where they are stored? how to track their expiry? If they contain user centric information then Can they be encrypted? Lets explore each of my question then we will go more into coding part of cookies. I remember the first definition of cookie that i learned “Cookie is a text file which is stored at the user’s hard disk and contains user’s session information” This definition is very much synonymous to Google definition: “A small sweet cake, typically round, flat, and crisp.” Good.Right? Our Cookie is a small file like small cake and provided sweet feeling by streamlining our session information. But when i really started working on cookies, I had my share of queries and resolutions like I came to know that as ‘http’ is a stateless protocol so we always have to attach our session information. What is this session information and why it is required every time? Well, the best answer is user expectations, we always want our web to be extra smart.Don’t we? if i say, you don’t have to sign in to your Gmail account on each request or you don’t have to add the items on your shopping basket every time or you just want your website to tell you,when you visited the site last time. This is the smart decisions we expect from our website but as HTTP protocol is stateless and can’t retain our information then what it did, it provided a Cookie mechanism to store the information at user’s side and send it to server on each request where it gets modified as per the request and sent back to the user to store it again. Here, I’ll sweetify the definition a bit: “Cookie is a piece of client’s information kept at client’s side in the form of a text file and , on each request and response, this information travels between the server and client” No files travels between server and client, only information travels in between server and client. At client side, information is read by the ‘HTTP’ request from this text file and while the response is received, this file is written with the updated information again. So where this file is located, It depends on the browser so let’s believe what we see now. In FireFox Run this: %AppData%\Mozilla\Firefox\Profiles\%FirefoxProfile%\cookies.sqlite To read the data you need to connect to that database and query the DB In Internet Explorer Run this : %AppData%\Microsoft\Windows\Cookies In Chrome Run this: %AppData%\\Google\Chrome\User Data\Default\Cookies Now, we...

Read More

Concepts: S O L I D

SOLID – Object oriented programming principles. May be its easy to forget these principles  but for creating a reusable code or maintainable code, people will always have to come back and check these principles for robust design. Today, We will explore these principles, not in terms of definition or meaning but why they are required or how they can help in designing our system. S –Single responsibility principle Wikipedia defines it as “every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class”. The idea behind this principle is that, if you have a class and there are some situation like there are dependent or inherited classes. there is some consumer flow attached to it. So if we go ahead and introduce any change to our main class then this change should only be limited to this class .  None of the dependent classes or consumers should have to be modified to adjust to this change. How and why? By following this principle, we can limit the number of places we have to change the code for a single change anywhere. It can facilitate clean code and division. Other than the advantages mentioned above, following this principle leads to Simple code. understandable design. Maintainability  O –Open/closed principle Wikipedia definition says “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification” When we write a code, we ,somewhat  has to predict the possible changes coming , as it is a well-known fact that the code that we are writing is susceptible to change when we are writing it. However if the developer is inexperienced and is not able to predict the possible changes, so to deal with  it ,go ahead and write the simple code. How and why? Although, the moment the changes are requested then he should be ready to introduce this principle and works on the extension of the code and make it more robust. As per the principle, software design should be open for extensions and closed for modifications . This is a tough prediction and involvement of  developer / designer is required to identify what areas of his code are susceptible to change. L – Liskov Substitution Principle Wikipedia definition – “if S is a subtype of T, then objects of type T may be replaced with objects of type S” This line always confused the readers as they talk about interchangeable principle  between base types and sub-types. if sub-types can replace base-types then why do we required base types at all? The primary objective of this design is that the code while calling should not know the difference between the base...

Read More
Page 1 of 3123