Java - object-oriented design Flashcards

1
Q

object-oriented design

A

In an object oriented manner, rather than a sequence of steps, you would create different self-contained programs. objects. Each object has its own list of what it can do. the objects let you re-use code in different ways.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

which languages are object-oriented

A

pretty much all of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

object

A

an instance of a class. inherits the behaviors and attributes of the class from which it was created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

three main aspects of an object

A

identity, attributes, and behaviors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

class

A

the template from which an object is created. when you create an object, you can instantiate it (create an instance of it) using parameters to initialize the object with specific values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

method

A

actions that the object can do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

function

A

a subroutine that might include certain actions or operations involving multiple objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

methods versus functions

A

Methods are defined as part of a class. Methods can access attributes from that class. But functions aren’t part of that class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Instantiation

A

creating an instance of a particular class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

built-in class

A

Many classes are already defined in object-oriented languages: Strings, Dates, Collections, File I/O, Networking, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Abstraction

A

“Data abstraction is the process of hiding certain details and showing only essential information to the user.

Focus on the essential qualities of something rather than one specific example. “Person” has a sense of an idea. You write one Person class with attributes (name, height, gender). If you don’t care about some of the attributes for your particular scenario, then you don’t need to define that in your object. To abstract something would be to look at all the objects and then abstract the original template from which these instances were created, or something.

literal definition of “abstract”: existing in thought or as an idea but not having a physical or concrete existence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Encapsulation

A

protecting an attribute for the class. This helps you restrict access to some of the object’s components. Let’s say you don’t want anyone to change some aspect of a class. If you change a number or something, it might be an invalid number. The attribute is kept inside the object. You use a method to modify the value in the class. The object doesn’t make known the attributes of things.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Black box testing

A

closing off the inner workings of the class and only revealing the inputs and outputs. You don’t need to know the guts of how something actually works to use it. You know, every time you make an include with parameters, it’s like object-oriented design. Those parameters get passed into some code logic that runs, and a return output is generated. You don’t need to know the details of the include, for the most part. The logic of the include is encapsulated away.

You don’t want to worry about other arguments that might break the logic of the code.

It’s not about being secretive. It’s about reducing dependencies. You want to safeguard the case where changing one value ends up messing up code elsewhere.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Inheritance

A

Base a new object or class on an existing one. the new object or class inherits the existing attributes and methods of the class it inherits. The child classes can also have their own unique attributes and methods.

To determine whether inheritance is happening, use “is a kind of.” or “is a type of.” Inheritance describes an “is a kind of like” relationships. e.g., a cargo shuttle is a space ship.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Polymorphism

A

Polymorphism means “many forms”, and it occurs when we have many classes that are related to each other by inheritance.

Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.

For example, think of a superclass called Animal that has a method called animalSound(). Subclasses of Animals could be Pigs, Cats, Dogs, Birds - And they also have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.):

Summary of polymorphism:

  • defining different classes that can be used with the same interfaces
  • using a method from the same class that can take different sets of parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

superclass

A

There’s no limit to the number of child classes you can create based on the parent. Benefits from code reuse. If you make a change in a superclass, that change bubbles down to each of the subclasses. e.g., if you add an email attribute to Person, then all the other subclasses based on person will also inherit this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

single inheritance

A

A subclass can only inherit from one parent.

18
Q

dynamic polymorphism

A

An object inherits methods from a class but then overwrites it within its own methods, or similar with other properties.

19
Q

method overloading

A

implementing multiple methods with the same name but different parameters. Not the same as method inheritance. You add more parameters into the method that you’re inheriting.

20
Q

class diagram

A

UML diagram to include name, attributes, and behaviors of the class

21
Q

functional requirements

A

a document that explains what an application must do. includes statements like, “the system must…”

22
Q

FURPS requirements

A
  • Functionality: capability, reusability, security
  • Usability: human factors, aesthetics, consistency, documentation
  • Reliability: Availability, Failure Rate and Duration, Predictability
  • Performance: Speed, Efficiency, Resource Consumption
  • Supportability: Testability, extensibility, configurability
23
Q

user stories

A

defining what the user’s requirements are. e.g., “as a user, i want to …”

24
Q

class

A

a blueprint. not usable in itself. only when you create instances of the class.

25
Q

instantiation

A

When you create an instance, you’re instantiating the object. You’re initializing the variables to some value. It allocates space in memory.

26
Q

object

A

an instance of a class

27
Q

constructor

A

used to instantiate an object. Initializes it with any particular values that need to be set. Constructor is a method by the same name as the class. No return type. Uses keyword new.

28
Q

overloading

A

classes that have multiple constructors with different parameters from the original class’ methods

29
Q

destructor

A

opposite of constructor. These methods destroys the object b/c it’s no longer needed. Reclaims that memory that the object was using.

30
Q

Static variables

A

Static variable — a variable that is shared across all objects in a class. There’s only one copy to update. a static variable is like a global variable. It’s global for that class, but not for the rest of the program. example:

31
Q

instance variable

A

In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated object of the class has a separate copy, or instance. An instance variable is similar to a class variable. … Variables are properties an object knows about itself.

32
Q

static method

A

In Java, a static method is a method that belongs to a class rather than an instance of a class. The method is accessible to every instance of a class, but methods defined in an instance are only able to be accessed by that member of a class.

33
Q

Overriding

A

allowing a subclass to replace the implementation of a method from the superclass

34
Q

super.[some method]

A

If you call a method in the superclass, calling it in the subclass, you put super before the method.

35
Q

abstract class

A

An abstract class is one that doesn’t ever get instantiated. instead, it just exists for the sake of being a base for others to inherit.

36
Q

interface

A

list of methods for a class to implement. doesn’t contain any actual behavior. Just a collection of method signatures that specify a service. Like some kind of behavior template. In the interface, the methods have no bodies. Instead, those method bodies are defined in the class that implements the interface. Method names, inputs, and outputs must match the interface. But you have total control over the bodies.

37
Q

DRY

A

don’t repeat yourself

38
Q

god object

A

have too much functionality

39
Q

factory method

A

Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

40
Q

code smell

A

any characteristic in the source code of a program that possibly indicates a deeper problem.