Focused more for interview Perspective and Easy Understanding
 Object-Oriented Programming (OOP) is a
software development paradigm that
suggests developers to split a program in
building blocks known as objects.
 The OOP paradigm allows developers to
define the object's data, functions, and its
relationship with other objects.
 Code Reusability
 Enables to model real world object
 Easy Modification
 Easy Maintenance
 More Flexible
 Defines an Abstract thing of a thing (i.e.
Object)
 Explaining its Behavior
 A user-defined data structure that groups
properties and methods.
 Class doesn’t occupies memory.
 Class is a definition
 Abstract classes are classes that can have no
instances
 A Single entity Which holds Data and Method.
 It’s Structure.
 Should be understandable by a non-
Programmer
DOG
(Class)
Color, Shape
(Characteristic)
Bark, Pee, Run
(Behaviors)
Members
Abstract characteristics
of a thing
Fields - _Color
Properties - Color
Fields - _Color
Properties - Color
 Specify Class Name
 Declare Data members
 Declare Methods
 Define the Processing
Program them in the following order:
 Namespace: The namespace is a keyword that
defines a distinctive name or last name for the
class. A namespace categorizes and organizes the
library (assembly) where the class belongs and
avoids collisions with classes that share the same
name.
 Class declaration: Line of code where the class
name and type are defined.
 Fields: Set of variables declared in a class block.
 Constants: Set of constants declared in a class
block.
 Constructors: A method or group of methods
that contains code to initialize the class.
 Properties: The set of descriptive data of an
object.
 Events: Program responses that get fired
after a user or application action.
 Methods: Set of functions of the class.
 Destructor: A method that is called when the
class is destroyed.
 In managed code, the Garbage Collector is in
charge of destroying objects; however, in some
cases developers need to take extra actions when
objects are being released, such as freeing
handles or de-allocating unmanaged objects.
 In .NET, there is no concept of deterministic
destructors. The Garbage Collector will call the
Finalize() method at a non-deterministic time
while reclaiming memory for the application.
Access keywords
 Access keywords define the access to class
members from the same class and from other
classes. The most common access keywords are:
 Public: Allows access to the class member from
any other class.
 Private: Allows access to the class member only
in the same class.
 Protected: Allows access to the class member
only within the same class and from inherited
classes.
 Internal: Allows access to the class member
only in the same assembly.
 Protected internal: Allows access to the class
member only within the same class, from
inherited classes, and other classes in the
same assembly. Static: Indicates that the
member can be called without first
instantiating the class.
 A particular Instance of a Class
 Objects are the building blocks of OOP
 Represent real world things in an abstract way
 Commonly defined as variables or data
structures that encapsulate behavior and data
in a programmed unit
 The objects will all act as independent units in
their own right, and they will be responsible
for carrying out a certain process
 Object identity:
 Every object is unique and can be differentiated from
other objects. Each time and object is created
(instantiated) the object identity is defined.
 Object behavior:
 What the object can do. In OOP, methods work as
functions that define the set of actions that the object
can do.
 Object state:
 The data stored within the object at any given
moment. In OOP, fields, constants, and properties
define the state of an object.
 Inheritance
 Abstraction
 Polymorphism
 Encapsulation
 Event
 Is like inheriting the abstract characteristics from
other class - It is a kind of hierarchy
 Base Class will be inherited to derived class
 is a way to form new classes using classes that
have already been defined
 is-a relationships represent a hierarchy between
classes of objects
 Use:
 Reuse of Code – uses the attributes of the base class
 Extensibility – Has it’s own Attributes
.Net Inheritance Concepts
March 15, 2004
Brian Berejik
Matt Jackson
Vinnie Alwani
 Simple / Single
 Multilevel
 Hierarchical
 Multiple
 Hybrid
 Superclass: Parent class
 Subclass: Child class
 Base class: Parent class
 Derived class: Child class
 Is like inheriting from more than one base
class.
 .Net do not allow. But using Multiple interface
inheritance this can be achieved.
 Information Hiding
 Visibility to the methods and not to the fields
 E.g. A Report designer for a programmer
 Packs the data and Method and protects from
external tampering
 Exposing only the details that are relevant: the
public interface
 Improves Security
 Protected cName as string
Protected Function ChangeName(NewName)
Me.cName = NewName
End Function
 As we cannot hide entire object we give access
to some specific part of data.
 Conceptual boundaries of an object
 Focuses on the essential characteristics of an
object
 a named entity made up of selected attributes
and behavior specific to a particular usage of
the originating entity
 Improves Security
For example see notes below
 One entity existing in multiple forms
 Behavior depends on the type of data
 Same message to diff objects results in
different behavior
 Linked to inheritance and assures that derived
class to override the implementation of
parents methods.
 Class Employee
Function PayEmployee()
PayEmployee = Hours * HourlyRate
End Function
 Class CommissionedEmployee
Inherits Employee
Overrides Function PayEmployee()
PayEmployee = BasePay + Commissions
End Function
 Upcasting
Casting an object of any type to another type
which is above it in the inheritance hierarchy.
 Downcasting
Casting an object of any type to another type
which is below it in the inheritance hierarchy.
Example
 Sealed Class
When applied to a class, the sealed modifier prevents
other classes from inheriting from it.
 static classes and static methods are used to create
data and functions that can be accessed without
creating an instance of the class.
class CompanyInfo {
public string GetCompanyName() { return "CompanyName"; }
public string GetComAddress() { return "ComAddress"; }
 These methods do not need to be attached to a
specific instance of the class. Therefore, instead of
creating unnecessary instances of this class, you can
declare it as a static class, like this:
static class CompanyInfo {
public static string GetCompanyName() {return "CompanyName";}
public static string GetComAddress() {return "ComAddress";}
 www.c-sharpcorner.com
 www.csharpcorner.com 2
 www.kuro5hin.org
 www.informit.com
 www.forums.asp.net
 www.developerfusion.com
 www.msdn.microsoft.com

oops-123991513147-phpapp02.pdf

  • 1.
    Focused more forinterview Perspective and Easy Understanding
  • 2.
     Object-Oriented Programming(OOP) is a software development paradigm that suggests developers to split a program in building blocks known as objects.  The OOP paradigm allows developers to define the object's data, functions, and its relationship with other objects.
  • 3.
     Code Reusability Enables to model real world object  Easy Modification  Easy Maintenance  More Flexible
  • 4.
     Defines anAbstract thing of a thing (i.e. Object)  Explaining its Behavior  A user-defined data structure that groups properties and methods.  Class doesn’t occupies memory.  Class is a definition  Abstract classes are classes that can have no instances
  • 5.
     A Singleentity Which holds Data and Method.  It’s Structure.  Should be understandable by a non- Programmer DOG (Class) Color, Shape (Characteristic) Bark, Pee, Run (Behaviors) Members Abstract characteristics of a thing Fields - _Color Properties - Color Fields - _Color Properties - Color
  • 6.
     Specify ClassName  Declare Data members  Declare Methods  Define the Processing
  • 7.
    Program them inthe following order:  Namespace: The namespace is a keyword that defines a distinctive name or last name for the class. A namespace categorizes and organizes the library (assembly) where the class belongs and avoids collisions with classes that share the same name.  Class declaration: Line of code where the class name and type are defined.  Fields: Set of variables declared in a class block.
  • 8.
     Constants: Setof constants declared in a class block.  Constructors: A method or group of methods that contains code to initialize the class.  Properties: The set of descriptive data of an object.  Events: Program responses that get fired after a user or application action.  Methods: Set of functions of the class.
  • 9.
     Destructor: Amethod that is called when the class is destroyed.  In managed code, the Garbage Collector is in charge of destroying objects; however, in some cases developers need to take extra actions when objects are being released, such as freeing handles or de-allocating unmanaged objects.  In .NET, there is no concept of deterministic destructors. The Garbage Collector will call the Finalize() method at a non-deterministic time while reclaiming memory for the application.
  • 11.
    Access keywords  Accesskeywords define the access to class members from the same class and from other classes. The most common access keywords are:  Public: Allows access to the class member from any other class.  Private: Allows access to the class member only in the same class.  Protected: Allows access to the class member only within the same class and from inherited classes.
  • 12.
     Internal: Allowsaccess to the class member only in the same assembly.  Protected internal: Allows access to the class member only within the same class, from inherited classes, and other classes in the same assembly. Static: Indicates that the member can be called without first instantiating the class.
  • 13.
     A particularInstance of a Class  Objects are the building blocks of OOP  Represent real world things in an abstract way  Commonly defined as variables or data structures that encapsulate behavior and data in a programmed unit  The objects will all act as independent units in their own right, and they will be responsible for carrying out a certain process
  • 14.
     Object identity: Every object is unique and can be differentiated from other objects. Each time and object is created (instantiated) the object identity is defined.  Object behavior:  What the object can do. In OOP, methods work as functions that define the set of actions that the object can do.  Object state:  The data stored within the object at any given moment. In OOP, fields, constants, and properties define the state of an object.
  • 15.
     Inheritance  Abstraction Polymorphism  Encapsulation  Event
  • 16.
     Is likeinheriting the abstract characteristics from other class - It is a kind of hierarchy  Base Class will be inherited to derived class  is a way to form new classes using classes that have already been defined  is-a relationships represent a hierarchy between classes of objects  Use:  Reuse of Code – uses the attributes of the base class  Extensibility – Has it’s own Attributes .Net Inheritance Concepts March 15, 2004 Brian Berejik Matt Jackson Vinnie Alwani
  • 17.
     Simple /Single  Multilevel  Hierarchical  Multiple  Hybrid
  • 18.
     Superclass: Parentclass  Subclass: Child class  Base class: Parent class  Derived class: Child class
  • 19.
     Is likeinheriting from more than one base class.  .Net do not allow. But using Multiple interface inheritance this can be achieved.
  • 20.
     Information Hiding Visibility to the methods and not to the fields  E.g. A Report designer for a programmer  Packs the data and Method and protects from external tampering  Exposing only the details that are relevant: the public interface  Improves Security
  • 21.
     Protected cNameas string Protected Function ChangeName(NewName) Me.cName = NewName End Function
  • 22.
     As wecannot hide entire object we give access to some specific part of data.  Conceptual boundaries of an object  Focuses on the essential characteristics of an object  a named entity made up of selected attributes and behavior specific to a particular usage of the originating entity  Improves Security For example see notes below
  • 23.
     One entityexisting in multiple forms  Behavior depends on the type of data  Same message to diff objects results in different behavior  Linked to inheritance and assures that derived class to override the implementation of parents methods.
  • 24.
     Class Employee FunctionPayEmployee() PayEmployee = Hours * HourlyRate End Function  Class CommissionedEmployee Inherits Employee Overrides Function PayEmployee() PayEmployee = BasePay + Commissions End Function
  • 25.
     Upcasting Casting anobject of any type to another type which is above it in the inheritance hierarchy.  Downcasting Casting an object of any type to another type which is below it in the inheritance hierarchy. Example  Sealed Class When applied to a class, the sealed modifier prevents other classes from inheriting from it.
  • 26.
     static classesand static methods are used to create data and functions that can be accessed without creating an instance of the class. class CompanyInfo { public string GetCompanyName() { return "CompanyName"; } public string GetComAddress() { return "ComAddress"; }  These methods do not need to be attached to a specific instance of the class. Therefore, instead of creating unnecessary instances of this class, you can declare it as a static class, like this: static class CompanyInfo { public static string GetCompanyName() {return "CompanyName";} public static string GetComAddress() {return "ComAddress";}
  • 27.
     www.c-sharpcorner.com  www.csharpcorner.com2  www.kuro5hin.org  www.informit.com  www.forums.asp.net  www.developerfusion.com  www.msdn.microsoft.com