Object Oriented Programming Concepts, using C#

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is Encapsulation

The inclusion, within an object, of all the resources (attributes, data & methods) it needs to function

What is a Class

a blueprint/plan/template for an object

What concepts group OOP system-design techniques

"A PIE" (mnemonics) 1. Abstraction 2. Polymorphism 3. Inheritance 4. Encapsulation

What modifiers are valid in C# interface methods (public, private, protected, internal, new, static

"new" is the ONLY valid modifier in an interface method. The method is, by default, also "public" & "abstract", but it should not be marked as such.

What is an Abstract class

1. A template, or "super-class", for other classes. 2. Contains at least one or more "stubs", or abstract methods/properties. 3. Can NOT be instantiated 4. Can be "extended" by another class by overriding ALL its abstract methods/properties. 5. Can have a default constructor, but it must be marked "protected", so it's "auto-called" while instantiating sub-class.

What basic (relationship) techniques can be used to "link" classes with each other

1. Association 2. Aggregation 3. Composition (note: each forms a 'subset' of the one above)

Why Software Architecture is important

1. Controls complexity 2. Enforces best practices 3. Gives consistency 4. Increases predictability 5. Enables re-use

What is an Interface

1. Defines a "contract", not an implementation. 2. Can have properties. 3. Method stubs and properties are, implicitly, public and abstract. 4. Can't be instantiated.

What is the goal of Software Architecture

1. Partition the problem 2. Create interfaces 3. Manage overall structure and flow 4. State how system interfaces with its environment 5. Recommend tools and techniques to build system

Describe how to mark a class that implements an interface, but not all of its methods.

1. Subclass must be marked abstract 2. Non-implemented methods/properties must be marked both: public & abstract

How do programming languages provide means to use generalization

1. variables 2. parametrization 3. generics 4. polymorphism

What is method overriding

A "virtual" method, if "overridden" in a subclass, causes the new method to be invoked on the object EVEN when the derived object is declared/used as if it were an instance of its base class. If you want the original method to still be available when the derived object is declared as base, use the "new" keyword instead of overriding.

What is the "Single Responsibility Principle" (SRP)

A class should have one, and only one, reason (or responsibility) to exist. That responsibility should be entirely encapsulated by the class.

What is "Aggregation"

A directional type of "Association" between classes that indicates inclusion and is usually stated using forms of the verb "to have", as in: companies have (sometimes) security-guards.

What is abstraction

A means to reduce complexity by hiding irrelevant details of an object & emphasizing its reason for existence, its qualities and its properties. It emphasizes the "what", rather than the "how".

What is generalization

A means to reduce complexity by replacing multiple entities that perform similar functions with a single one. I.E.: the overloading of the "+" operator to work on numbers (addition) and strings (concatenation)

What is operator overloading

A type of method polymorphism that causes operators (+, -, ==, *) to behave differently depending on the type of its arguments.

What is "Composition"

An "Aggregation" of one class within another which indicates that the lifetime of the two classes is linked: like University and Faculties. It's usually stated by the phrase "composed of", as "a University is composed of faculties. If the university closes ... the (isolated) existence of its faculties does not make sense.

What is the Dependency Inversion Principle (DIP)

Depend on generalities (abstractions), not on concrete implementations.

What is the Liskov Substitution Principle (LSP)

If a statement is true for a base class, then you should be able to use (in the statement) an instance of a derived class. The statement should still be valid. I.E.: if the class "animal" has a certain capability ... then so should the class "dog", if "dog" is derived from "animal".

If a method is declared "virtual" in a base class, what is the difference between "overriding" it, or marking it "new", in a derived class.

If an object, Obj, is defined as an instance of a derived class, then: 1. If a method is overridden in the derived class Obj will use the overridden method whether or not Obj is declared as base or as derived. 2. If a method is declared "new" in the derived class, Obj will use the base method if it is declared as base ... and the "new" method if it is declared as derived.

What is method overloading

Is a form of method polymorphism: the ability to define several methods all with the same name.

What is an Object

It can be considered a "thing" that can perform a set of related activities. In OOP terms it is an "instance" of a class.

What is a "use case"

It is the description of what an "actor" (not necessarily a person) perceives when using a function of a software system.

What is the Interface Segregation Principle (ISP)

Make fine grained interfaces that are client specific.

What is (object) polymorphism

Means: "many-shaped", and means an object can behave as an instance of multiple classes. 1. at run-time (as a parameter, etc) the object may be treated as being an instance of: i) the class that was used to instantiate it. ii) any of its base classes. 2. base class "virtual" methods can be "overridden" by the derived class and thus be called on the object EVEN when the object is declared an instance of the base class.

What is "Association"

Most general relationship between classes, as: companies "use" security guards (but don't HAVE to).

Can a C# class, or interface, be nested within another interface

No, classes and interfaces can NOT be nested within another interface.

Assuming the following class/interface are at a global scope (not nested within another class or interface): are these snips of code OK?: protected class MyClass{ ... } protected interface MyInterface{ ... }

No, the ONLY access modifiers valid on a (global) class/interface are "public" and "internal"

What method modifier (public, private, ... etc) are allowed on interface methods.

Only the "new" modifier is allowed, indicating that it hides a method of the same name on an inherited interface.

Name 5 principles to follow in designing a class

S.O.L.I.D. 1. SRP - Single Responsibility 2. OCP- Open Closed 3. LSP - Liskov Substitution 4. ISP - Interface Segregation 5. DIP - Dependency Inversion

What is the Open Closed Principle (OCP)

You should be able to extend a class behavior without modifying it.

If a class, interface or struct is not marked with an access modifier, what access level does it get by default: public, private, protected, internal

internal


Conjuntos de estudio relacionados

CONTRACTS - The Parol Evidence Rule

View Set

What is life? A Guide to Biology: Chapter 1

View Set

AP Comparative Government Review Questions (Iran)

View Set

Chapter 13: Marketing Helps Buyers Buy

View Set

تاريخ قطر واثر القبائل

View Set

Chapter 2: Developing Strong Listening and Communication Skills

View Set