Object Oriented Programming in C#

Object Oriented Programming in C#

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

What is a class contract?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (53)

Section 1

(50 cards)

What is a class contract?

Front

The publicly exposed methods (or functions) and properties (or fields or attributes) of that class interface along with any comments or documentation that apply to those public methods and properties. The class contract is also called the class interface.

Back

What is an Entity?

Front

Any object that is defined by a class is referred to as an entity. Ex:

Back

What the AAA method of setting up Unit Tests?

Front

Arrange -> Sets up the test Act -> Contains the code being tested Assert -> Verifies the result of the test

Back

What are the 3 basic types of Object Relationships?

Front

1. Collaboration ("uses a") -> Customer Repository uses a Customer 2. Composition ("has a") -> Order has a Customer, Address, and Order Item - Aggregation -> type of composition in which component parts do not exist except as a Composition -> Order Item does not exist without Order 3. Inheritance ("is a") -> Customer is a Government type Customer

Back

What are some Object class methods in C#?

Front

1. ToString() -. "System.Object" 2.

Back

What is abstraction?

Front

Abstraction is a process of hiding the implementation details and showing only functionality to the user. Abstraction lets you focus on what the object does instead of how it does it. - Simplifying reality - Ignoring extraneous details - Focusing on what is important for a purpose

Back

Techniques for Reuse

Front

1. Collaboration 2. Inheritance 3. Components

Back

What is a default constructor?

Front

The default constructor is a constructor that doesn't take in data, it simply initializes the data for the other constructors in the class to utilize. It has no parameters. If you don't need to add any default values, aside from those already defined as properties, a default empty constructor will be created for you.

Back

What is the difference between IEnumerable<string> and List<string>?

Front

IEnumerable is an interface which List implements. IEnumerable is a sequence of string whereas List in indexable by an int index, which can add and remove at certain indexes. A List is a specific random-access variable-size collection. IEnumerable has better performance than List.

Back

What is an IEnumerable?

Front

The recommended way to return a sequence of data because the results are more flexible for the callers of the method.

Back

What is method overriding?

Front

Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the superclass by providing the same method name, same parameter and same return type. Syntax: override ToString() is... public override string ToString() { return base.ToString(); } An overridden function is a method in a descendant class that has a different definition than a virtual function in an ancestor class. The compiler chooses which function is desired based upon the type of the object being used to call the function.

Back

What is method overloading?

Front

If a class have multiple methods by same name but different parameters, it is known as Method Overloading. It increases the readability of the program. They should provide variations of the same functionality. An overloaded function is a function that shares its name with one or more other functions, but which has a different parameter list. The compiler chooses which function is desired based upon the arguments used.

Back

How does the static modifier affect a class property or method?

Front

It declares a member that belongs to the class itself, instead of a reference to the class object (or an instance of the class object). It is accessed using the class name, not an object variable.

Back

What is the method redefining?

Front

A redefined function is a method in a descendant class that has a different definition than a non-virtual function in an ancestor class. Don't do this. Since the method is not virtual, the compiler chooses which function to call based upon the static type of the object reference rather than the actual type of the object.

Back

What does the Abstract keyword do to methods?

Front

The abstract keyword marks a method which must be overridden in the class's derived classes. It does not have it's own implementation and so does not have a statement body. Ex: public abstract bool Validate();

Back

What is the YAGNI principal?

Front

You Ain't Gonna Need It. Avoid adding unnecessary features based on potential future needs.

Back

What is a class constructor?

Front

A class constructor is code that is executed every time an instance of the class is created. It is named with the class name. ( C# shortcut -> ctor )

Back

What is inheritance?

Front

Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding. The child class (or derived class) inherits from the parent class (or base class).

Back

What is encapsulation?

Front

Surrounding something, not just to keep the contents together, but also to protect those contents. Restricts access to the inner workings of a class or any objects based on that class; this is referred to as information hiding or data hiding.

Back

3 Basic Layers of Applications

Front

1. User Interface (View) 2. Business Logic (Model) 3. Data Access (Controller)

Back

What is an interface??

Front

An interface is a class that only includes method signatures. The methods are not implemented in the interface. Another class must be created to supply the implementation. Ex: public interface ILoggable string Log();

Back

How does encapsulation enable data hiding?

Front

It protects the data by allowing for authorization before GETTING the data, and validation when SETTING the data.

Back

What is inheritance-based polymorphism?

Front

A single method can behave differently depending on the type of object that calls it.

Back

What is a Nullable Type and how is it defined within C#?

Front

Defined by the ? character (ex: Decimal? in a property name). A nullable type is a value type such as an integer or decimal that allows definition of the value type or a null.

Back

What is an extension method?

Front

An extension method is a way of extending static methods to use it in a derived class like an instance type method. An extension method must reside in a static class and the method it is extending must be static. Ex: public static class StringHandler { public static string InsertSpaces(this string source) then... productName.InsertSpaces();

Back

Difference between object and class

Front

Class contains methods and properties of an object. Provides definition for a particular type of object. Object is an instance of a class. Object variable holds the state of the object.

Back

What is cohesion?

Front

Cohesion is the degree to which members of the class relate to the purpose of the class. High cohesion means that a feature request will likely only affect a small number of classes, simplifying maintenance.

Back

What are access modifiers?

Front

Access modifiers determine the scope of the method or variables that can be accessed from other various objects or classes. There are 5 types of access modifiers , and they are as follows:. Private - only the base class can access Protected - the base class and all of its derived classes can access Public - any class in the namespace can access

Back

How does encapsulation enable implementation hiding?

Front

It helps to manage the complexity of a program because only the class needs to understand the implementation details, and the implementation can be changed without affecting the rest of the application.

Back

What is the difference between an Abstract class and a Concrete class?

Front

An Abstract class cannot be instantiated (To instantiate a class is to create an object). It is intended only to be used as a base class for other classes. A Concrete class can be instantiated.

Back

What is a Collaboration Object Relationship?

Front

Exists when a class uses an instance of another class.

Back

What is the difference between value types and reference types?

Front

Value types store their data directly. Reference types store references to their data.

Back

What is the difference between an implicit and explicit class interface?

Front

The implicit class interface is the set of public properties and methods in a class are automatically included in the class's interface. The explicit class interface is defined with the interface keyword, and does not provide any implementation. It is reuseable across other classes. The explicit interface defines the role an object can play.

Back

Can you inherit from more than one class in C#?

Front

No. It does not support multiple inheritance.

Back

Are objects Reference or Value Types?

Front

Objects are reference types, unless the static modifier is used on a property or method, which makes it act as a value type.

Back

What are some examples of .NET interfaces?

Front

1. IDisposable 2. IEquatable 3. IComparable 4. INotifyPropertyChanged 5. IEnumerable 6. IObservable

Back

What is a Sealed class?

Front

Sealed classes are those classes which can not be inherited and thus any sealed class member can not be derived in any other class. This prevents extension and customization.

Back

What is the enum type?

Front

An enumerated type is a set of named constants. Ex: enum <enum_name> { enumeration list }; enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat }

Back

What is a Business Object?

Front

Business object often refers to classes.

Back

What is polymorphism?

Front

A single method, such as a ToString() method, can behave differently depending on the type of object that calls it. It allows you to work with a group of classes in a uniform way. There are different types: 1. Inheritance-based Polymorphism - A base class defines a method, and a derived class overrides that method to define its own unique definition and implementation.

Back

What does a separation of concerns accomplish?

Front

- Minimizes coupling - Maximizes cohesion - Simplifies maintenance - Improves testability Decompose an application into parts with minimal overlap (coupling). Each part is responsible for a separate concern (cohesion).

Back

What are Design Patterns?

Front

Recurring, reusable solutions to common class and class relationship problems. Example: storing CRUD methods in a Repository class (Repository Pattern).

Back

What is Constructor Chaining?

Front

One constructor calls another constructor.

Back

What is coupling?

Front

The degree to which two classes are dependent on each other. Low coupling is always the goal, and that means that changes to one class are not as likely to adversely affect another class, which makes maintenance easier. It also makes is easier to test a class, since it has minimal dependency on other classes.

Back

What does the Virtual keyword do?

Front

In a method, a virtual marked method has it's own implementation but allows for the method to be overridden. It does not have to be overridden (unlike abstract methods).

Back

What is a Composition Object Relationship?

Front

Exists when an object is composed of one or more objects from another class. Composite objects often contain references to their component objects as properties.

Back

What is a circular reference?

Front

When two different projects reference each other.

Back

What is OOP?

Front

"Object-oriented programming (OOP) is a programming paradigm using ""objects"" - data structures consisting of data fields and methods together with their interactions - to design applications and computer programs. There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation. Other parts include data abstraction, messaging and modularity."

Back

What are the four main pillars of OOP?

Front

Four main pillars: 1. Abstraction 2. Encapsulation 3. Polymorphism 4. Inheritance

Back

What is a method signature?

Front

A method signature is the method's name and type of each of its parameters. It does not include it's return type.

Back

Section 2

(3 cards)

What are Nullable Types in C#?

Front

A value type that can be made nullable. Ex: Nullable<T> Nullable<string> or string?

Back

List Differences between value and reference types

Front

Back

What is the difference between a class and a struct?

Front

A structure is a value type while a class is a reference type. A structure does not support inheritance (but can implement interfaces). A structure cannot have a default constructor.

Back