The document discusses object-oriented programming concepts in C#, including abstract classes, sealed classes, interfaces, and file input/output operations. Abstract classes provide a partial implementation of an interface and contain abstract methods to be implemented in derived classes. Sealed classes cannot be inherited from. Interfaces define properties and methods without implementation. File input/output uses streams to read from and write to files, with the FileStream class opening and accessing files.
How to Troubleshoot Apps for the Modern Connected Worker
08 iec t1_s1_oo_ps_session_11
1. Object-Oriented Programming Using C#
Objectives
In this session, you will learn to:
Use abstract classes
Use sealed classes
Use interfaces
Implement the file input and output operations
Ver. 1.0 Session 11 Slide 1 of 16
2. Object-Oriented Programming Using C#
Using Abstract Classes
C# enables you to create abstract classes that are used to
provide partial class implementation of an interface.
Abstract classes contain abstract methods, which can be
implemented by the derived class.
Polymorphism can be implemented by using abstract
classes and virtual functions.
There are certain rules governing the use of an abstraction
class:
Cannot create an instance of an abstract class.
Cannot declare an abstract method outside an abstract class.
Cannot be declared sealed.
Ver. 1.0 Session 11 Slide 2 of 16
3. Object-Oriented Programming Using C#
Using Abstract Methods
Abstract methods are methods without any body.
The implementation of an abstract method is done by the
derived class.
When a derived class inherits the abstract method form the
abstract class, it must override the abstract methods. This
requirement is enforced at compile time, and is also called
dynamic polymorphism.
The syntax for using the abstract method is as follows:
[access-modifiers] abstract return-type method
name (parameters]);
The abstract method is declared by adding the abstract
modifier to the method.
Ver. 1.0 Session 11 Slide 3 of 16
4. Object-Oriented Programming Using C#
Using Virtual Functions
• When you have a function defined in a class which you
want to allow to be implemented by the inherited classes,
you can use virtual function.
• The virtual function could be implemented by the
inherited classes in their own way and the call to the
method is decided at the run time.
Ver. 1.0 Session 11 Slide 4 of 16
5. Object-Oriented Programming Using C#
Using Sealed Classes
• You could restrict users form inheriting the class by sealing
the class using the sealed keyword.
• The sealed keyword tells the compiler that the class is
sealed, and therefore, cannot be extended.
• The following is an example of a sealed class:
sealed class FinalClass
{
private int x;
public void Method1()
{
}
}
A method can also be sealed and in that case the method
cannot be overridden.
Ver. 1.0 Session 11 Slide 5 of 16
6. Object-Oriented Programming Using C#
Using Interfaces
Interfaces define properties, methods, and events, which
are known as the members of the interface.
Interfaces are fully supported by C#.
Interfaces are used when a standard structure of methods is
to be followed by the classes, and where classes will
implement the functionality.
Interfaces separate the definition of objects from their
implementation so that the objects can evolve without the
risk of introducing incompatibility in existing applications.
Ver. 1.0 Session 11 Slide 6 of 16
7. Object-Oriented Programming Using C#
Working with Interfaces
• Working with interfaces includes interface declaration and
implementation of interface by the classes.
• You can declare interfaces using the interface keyword.
• Interface statements are public, by default.
• You can declare only methods, functions, and properties in
interfaces. You cannot declare a variable in interfaces.
• Interfaces declare methods, which are implemented by
classes. A class can inherit from single class but can
implement form multiple interfaces.
Ver. 1.0 Session 11 Slide 7 of 16
8. Object-Oriented Programming Using C#
Inheriting Interfaces
A class or a structure that implements interfaces also
implements the base interfaces of the inherited interface.
Ver. 1.0 Session 11 Slide 8 of 16
9. Object-Oriented Programming Using C#
Demo: Order-Processing System Using Abstract Classes
Problem Statement:
Furniture and Fittings Company (FFC) manufactures domestic
furniture. Customers provide their specifications to the
company for the furniture they want. To cope with the received
customer’s orders, FFC decides to computerize the
order-processing system. The system should accept the values
of furniture items, such as a bookshelf and a chair. You need
to develop the hierarchy of these items.
Ver. 1.0 Session 11 Slide 9 of 16
10. Object-Oriented Programming Using C#
Demo: Order-Processing System Using Abstract Classes (Contd.)
Solution:
To create a console based application for FFC, you need to
perform the following tasks:
1. Create a console-based application.
2. Build and execute an application.
Ver. 1.0 Session 11 Slide 10 of 16
11. Object-Oriented Programming Using C#
Implementing the File Input and Output Operations
• The stream is a sequence of bytes traveling from a source
to a destination over a communication path.
• The two basic streams used are the input and output
streams.
• An input stream is used for a read operation and an output
stream is used for performing a write operation.
• The System.IO namespace includes various classes, which
are used to perform operations, such as file creation, file
deletion, and the read-write operations to files.
Ver. 1.0 Session 11 Slide 11 of 16
12. Object-Oriented Programming Using C#
FileStream Class
• To open an existing file or to create a new file, you need to
create an object of type FileStream.
• Consider the following syntax for creating the object of type
FileStream:
FileStream <object name>=new FileStream(<file
Name>,<FileMode Enumerator>,<File Access
Enumerator>,<FileShare Enumerator>);
Ver. 1.0 Session 11 Slide 12 of 16
13. Object-Oriented Programming Using C#
FileStream Class (Contd.)
• FileMode enumerator defines various methods for opening
files.
• The FileMode enumerator parameter is specified in many
constructors for the FileStream.
• The parameters to FileMode checks whether a file is
overwritten, created, or opened.
• FileAccess enumerator indicates whether you want to read
data from the file, write to the file, or perform both the
operations.
• The members of the FileAccess enumerator are Read,
ReadWrite, and Write.
Ver. 1.0 Session 11 Slide 13 of 16
14. Object-Oriented Programming Using C#
FileStream Class (Contd.)
The FileShare enumerator contains constants for
controlling the kind of access that the other FileStream
constructors can have to the same file.
A typical use of this enumeration is to define whether two
different applications can simultaneously read from the
same file.
Ver. 1.0 Session 11 Slide 14 of 16
15. Object-Oriented Programming Using C#
Summary
In this session, you learned that:
– An abstract superclass is a conceptual class that does not
exist in real world but acts as a base from which other classes
inherit properties behavior.
– A sealed class tells the compiler that the class cannot be
extended further. You cannot derive a class from a sealed
class.
– An interface defines properties, methods, and events. The
properties, methods, and events that are defined in the
interface are known as the members of the interface.
– A stream is an abstraction of a sequence of bytes traveling
from a source to a destination over a communication path.
Ver. 1.0 Session 11 Slide 15 of 16
16. Object-Oriented Programming Using C#
Summary (Contd.)
– The two basic streams used are the input and output streams.
An input stream is used for a read operation and an output
stream is used for performing a write operation.
– Most file input/output (I/O) support in the .NET Framework is
implemented in the System.IO namespace. You can use the
FileStream class in the System.IO namespace to read
from, to write, and to close files.
– The FileStream class inherits from the abstract class
Stream.
Ver. 1.0 Session 11 Slide 16 of 16
Notes de l'éditeur
Students have learnt the structure of different types of dimensions and the importance of surrogate keys in Module I. In this session, students will learn to load the data into the dimension tables after the data has been transformed in the transformation phase. In addition, students will also learn to update data into these dimension tables. Students already know about different types of dimension tables. Therefore, you can start the session by recapitulating the concepts. Initiate the class by asking the following questions: 1. What are the different types of dimensions? 2. Define flat dimension. 3. What are conformed dimension? 4. Define large dimension. 5. Define small dimension. 6. What is the importance of surrogate key in a dimension table? Students will learn the loading and update strategies theoretically in this session. The demonstration to load and update the data in the dimension table will be covered in next session.
Student already have learnt about type 2 SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 2 SCDs? Given an example to explain type 2 SCDs. This will recapitulate what they have learnt about type 2 SCD in Module 1. Now explain the strategy to update the data into these dimension tables with help the example given in SG. After explaining the examples, you can ask students to think of an example of a type 2 SCD and then tell the strategy to update the data into this dimension table.
Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
Student already have learnt about SCDs in Module I. Therefore, you can start this topic by asking the following questions to students: What are type 1 SCDs? Given an example to explain type 1 SCDs. This will recapitulate what they have learnt about type 1 SCD in Module 1. Now explain the strategy to load the data into these dimension tables with help of the given diagram. Relate this diagram to the example given in SG.
Students have learnt the structure of different types of dimensions and the importance of surrogate keys in Module I. In this session, students will learn to load the data into the dimension tables after the data has been transformed in the transformation phase. In addition, students will also learn to update data into these dimension tables. Students already know about different types of dimension tables. Therefore, you can start the session by recapitulating the concepts. Initiate the class by asking the following questions: 1. What are the different types of dimensions? 2. Define flat dimension. 3. What are conformed dimension? 4. Define large dimension. 5. Define small dimension. 6. What is the importance of surrogate key in a dimension table? Students will learn the loading and update strategies theoretically in this session. The demonstration to load and update the data in the dimension table will be covered in next session.
Students have learnt the structure of different types of dimensions and the importance of surrogate keys in Module I. In this session, students will learn to load the data into the dimension tables after the data has been transformed in the transformation phase. In addition, students will also learn to update data into these dimension tables. Students already know about different types of dimension tables. Therefore, you can start the session by recapitulating the concepts. Initiate the class by asking the following questions: 1. What are the different types of dimensions? 2. Define flat dimension. 3. What are conformed dimension? 4. Define large dimension. 5. Define small dimension. 6. What is the importance of surrogate key in a dimension table? Students will learn the loading and update strategies theoretically in this session. The demonstration to load and update the data in the dimension table will be covered in next session.
Students know the importance of surrogate keys. In this session students will learn the strategy to generate the surrogate key. Give an example to explain the strategy to generate the surrogate keys by concatenating the primary key of the source table with the date stamp. For example, data from a Product table has to be loaded into the Product_Dim dimension table on Feb 09, 2006. The product_code is the primary key column in the Product table. To insert the surrogate key values before loading the data into the dimension table, you can combine the primary key value with the date on which the data has to be loaded. In this case the surrogate key value can be product_code+09022006.
Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
Students know what is the structure of Flat dimension. You can initiate the session by asking the following questions: 1. What are flat dimension tables? 2. What is the structure of flat dimension? 3. Given examples of a flat dimension? Next, tell the strategy to load the data into the flat dimension table. You can explain the loading strategy with the help of the example given in SG. Continue this session by asking the following questions: 4. What are large flat dimension tables? 5. Give examples of large flat dimensions? Then, explain the strategy to load data into the large flat dimension table. Before explaining the strategy to load data into the small dimension table ask the following questions and the tell the strategy to load the data into the dimension table. 6. What are small flat dimension tables? 7. Give examples of small flat dimension tables. With the help of these questions, students will be able to recall about flat dimensions, they have learnt in Module I. Explain this topic with the help of an example given in SG.
You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.
You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.