Posts

Understanding Interface

Interface used to establish contracts through which objects can interact with each other without knowing the implementation details. Interfaces are defined by using the interface keyword. An interface definition consists a set of signature for methods, delegates, events or indexers. An interface cannot consist of any data fields or any implementation details such as methods body. Icomparable interface A common interface defined in the system namespace is the Icomparable.  Icomparable definition:   interface Icomparable  {          int compareTo(object obj); } The Icomparale has a single method that accepts an object and returns an int. The return value of this method indicates the result of comparing the given parameter with the current object. CompareTo method documentation If the instance is equal to the parameter, CompareTo returns 0. If the parameter value is less then the instance or if...

Understanding Polymorphism

Image
Polymorphism is the ability of the derived classes to share common functionality with base classes but still define their own unique behaviour. You are developing an application that allows users to work with a different kind of polygon.  You have a collection that store a different type of polygons, such as Rectangle, Triangle and square. Each polygon provides its own implementation of the method Draw. When working with the collection you don't necessarily know exactly which shape you are working with, but you would like the correct Draw method to be invoked each time.  polymorphism enable you to do it.    Polymorphism allows the objects of the derived class to be treated at runtime as objects of the base class. Understanding the Override and New Keywords The override keyword replaces a base class member in a derived class. 3. You created a class named GeoShape. You defined a method called Area in the Ge...

Understanding Encapsulation

Encapsulation Is an information-hiding mechanism that makes code easy to maintain and to understand.  Encapsulation is a mechanism to hide a class or members of a class in order to hide design decisions that are likely to change. Encapsulation gives the class designer the flexibility to change some section of the code without changing all of the other code that makes use of that code.  Properties are a great way to hide data fields. Understanding Access Modifiers Access modifiers control where a type or type member can be used. All types and type members have an access level that specifies where that class or its members can be used in your code. Public Access is not restricted. Private Access is restricted to the containing class. Protected Access is restricted to the containing class and to and class that derived directly or indirectly from the containing class. Internal Access is restricted to the ...

Understanding Value and Referance

Image
Understanding Structs The keyword struct is used to create a user-defined type that contains a small of related fields. Structs are value type as opposed to classes, which are a reference type. Define a struct Public Struct Point {       public double x,y; } Struct can contain  Contractors Methods Properties Structs cannot inherit from another class or structs. Understanding Memory Allocation After you enter a value or text into a cell, you can modify it in a number of ways. In particular, you can remove the contents completely, enter a different value to replace what was there, or alter what you have entered. When you create a value type for example int, a named memory is created. If you didn't assign any value to the variable then the default value is null. When you assign the value, the memory address is identified by the memory variable name and updated. When you create a reference...

Understanding Static Members

Image
Static members  belong to the class itself rather than individual objects. Instance members They can be used only after an instance of a class is created. Static members Is used to declared members that do not belong to individual objects but to a class itself. one common example is the main method that serves as the entry point. Static members belong to the class itself, not the instance that created from the class.  When an instance of a class created A separate copy is created for each instance field. But only one copy of static field is shared by all instance. All things that you create are non-static by default. What can you make static Classes Method properties What static means: Does not belong to any object instance created, it belongs to the class itself. A class is a template and object is created from that template so it's instantiated from that template. that is the class. When we make som...