C#에서의 객체지향에 관한 PPT입니다
필자의 생각과 경험으로 만든 자료라 일반적인 교육 자료와 사용하는 용어 등이 매우 다를 수 있습니다.
---------------------------------------------------
PPT about Object-Oriented Programming in C# Language
자프링(자바 + 스프링) 외길 12년차 서버 개발자가 코프링(코틀린 + 스프링)을 만난 후 코틀린의 특징과 스프링의 코틀린 지원을 알아가며 코프링 월드에서 살아남은 이야기…
코드 저장소: https://github.com/arawn/kotlin-support-in-spring
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
자프링(자바 + 스프링) 외길 12년차 서버 개발자가 코프링(코틀린 + 스프링)을 만난 후 코틀린의 특징과 스프링의 코틀린 지원을 알아가며 코프링 월드에서 살아남은 이야기…
코드 저장소: https://github.com/arawn/kotlin-support-in-spring
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
NHN NEXT 게임 서버 프로그래밍 강의 자료입니다. 최소한의 필요한 이론 내용은 질문 위주로 구성되어 있고 (답은 학생들 개별로 고민해와서 피드백 받는 방식) 해당 내용에 맞는 실습(구현) 과제가 포함되어 있습니다.
참고로, 서버 아키텍처에 관한 과목은 따로 있어서 본 강의에는 포함되어 있지 않습니다.
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
While Java’s strict type system is a great help for avoiding programming errors, it also takes away some of the flexibility that developers appreciate when using dynamic languages. By using runtime code generation, it is possible to bring some of this flexibility back to the Java virtual machine. For this reason, runtime code generation is widely used by many state-of-the-art Java frameworks for implementing POJO-centric APIs but it also opens the door to assembling more modular applications. This presentation offers an introduction to the complex of runtime code generation and its use on the Java platform. Furthermore, it discusses the up- and downsides of several code generation libraries such as ASM, Javassist, cglib and Byte Buddy.
Domain Driven Design with the F# type System -- NDC London 2013Scott Wlaschin
(Video of these slides here http://fsharpforfunandprofit.com/ddd)
Statically typed functional programming languages like F# encourage a very different way of thinking about types. The type system is your friend, not an annoyance, and can be used in many ways that might not be familiar to OO programmers.
Types can be used to represent the domain in a fine-grained, self documenting way. And in many cases, types can even be used to encode business rules so that you literally cannot create incorrect code. You can then use the static type checking almost as an instant unit test — making sure that your code is correct at compile time.
In this talk, we'll look at some of the ways you can use types as part of a domain driven design process, with some simple real world examples in F#. No jargon, no maths, and no prior F# experience necessary.
Code, links to video, etc., at http://fsharpforfunandprofit.com/ddd
For more on DDD and F# see:
http://fsharpforfunandprofit.com/ddd/
http://tomasp.net/blog/type-first-development.aspx/
http://gorodinski.com/blog/2013/02/17/domain-driven-design-with-fsharp-and-eventstore/
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
Class is template for an object and object is instance of a class.
When we create a class, we are creating a new data type. we can use this type to declare objects of that type.
여러 언어에서 null 안전성을 주요 마케팅 쟁점으로 내세우면서 null 안전성이 관심을 많이 받고 있습니다.
자바에서도 null을 잘 다루어야 소프트웨어 결함을 줄이고 견고하게 만들 수 있는데 null의 위협에서 코드를 안전하게 지키는 설계 지침을 정리하고 안전하다고 확인하는데 도움이 되는 도구를 소개합니다.
배민찬(https://www.baeminchan.com) 서비스의 백엔드 시스템 중 일부가 지난 1년간 어떤 고민과 아이디어, 결과물을 만들어냈는지 공유하려고 합니다. 발표 중 언급되는 용어나 도구에 대해 일반적인 정의나 간단한 설명은 언급되나 자세히 다루지 않습니다. 사용된 도구들로 어떻게 이벤트 기반 분산 시스템을 만들었는지에 대한 이야기가 중심입니다.
in these slides i have explained the factory method design pattern. slides contains complete notes on this pattern from definition to implementation by code example.
NHN NEXT 게임 서버 프로그래밍 강의 자료입니다. 최소한의 필요한 이론 내용은 질문 위주로 구성되어 있고 (답은 학생들 개별로 고민해와서 피드백 받는 방식) 해당 내용에 맞는 실습(구현) 과제가 포함되어 있습니다.
참고로, 서버 아키텍처에 관한 과목은 따로 있어서 본 강의에는 포함되어 있지 않습니다.
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
While Java’s strict type system is a great help for avoiding programming errors, it also takes away some of the flexibility that developers appreciate when using dynamic languages. By using runtime code generation, it is possible to bring some of this flexibility back to the Java virtual machine. For this reason, runtime code generation is widely used by many state-of-the-art Java frameworks for implementing POJO-centric APIs but it also opens the door to assembling more modular applications. This presentation offers an introduction to the complex of runtime code generation and its use on the Java platform. Furthermore, it discusses the up- and downsides of several code generation libraries such as ASM, Javassist, cglib and Byte Buddy.
Domain Driven Design with the F# type System -- NDC London 2013Scott Wlaschin
(Video of these slides here http://fsharpforfunandprofit.com/ddd)
Statically typed functional programming languages like F# encourage a very different way of thinking about types. The type system is your friend, not an annoyance, and can be used in many ways that might not be familiar to OO programmers.
Types can be used to represent the domain in a fine-grained, self documenting way. And in many cases, types can even be used to encode business rules so that you literally cannot create incorrect code. You can then use the static type checking almost as an instant unit test — making sure that your code is correct at compile time.
In this talk, we'll look at some of the ways you can use types as part of a domain driven design process, with some simple real world examples in F#. No jargon, no maths, and no prior F# experience necessary.
Code, links to video, etc., at http://fsharpforfunandprofit.com/ddd
For more on DDD and F# see:
http://fsharpforfunandprofit.com/ddd/
http://tomasp.net/blog/type-first-development.aspx/
http://gorodinski.com/blog/2013/02/17/domain-driven-design-with-fsharp-and-eventstore/
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
Class is template for an object and object is instance of a class.
When we create a class, we are creating a new data type. we can use this type to declare objects of that type.
여러 언어에서 null 안전성을 주요 마케팅 쟁점으로 내세우면서 null 안전성이 관심을 많이 받고 있습니다.
자바에서도 null을 잘 다루어야 소프트웨어 결함을 줄이고 견고하게 만들 수 있는데 null의 위협에서 코드를 안전하게 지키는 설계 지침을 정리하고 안전하다고 확인하는데 도움이 되는 도구를 소개합니다.
배민찬(https://www.baeminchan.com) 서비스의 백엔드 시스템 중 일부가 지난 1년간 어떤 고민과 아이디어, 결과물을 만들어냈는지 공유하려고 합니다. 발표 중 언급되는 용어나 도구에 대해 일반적인 정의나 간단한 설명은 언급되나 자세히 다루지 않습니다. 사용된 도구들로 어떻게 이벤트 기반 분산 시스템을 만들었는지에 대한 이야기가 중심입니다.
in these slides i have explained the factory method design pattern. slides contains complete notes on this pattern from definition to implementation by code example.
테크데이즈 코리아 2014 에서 "The Future of C# and .NET Framework"라는 제목으로 발표한 슬라이드 입니다. 관련 동영상 : http://www.microsoftvirtualacademy.com/training-courses/-techdays-korea-2014-t14
NDC2016에서 발표한 카툰999의 포스트모템 발표입니다.
피드백의 힘이라는 주제로 카툰999를 개발하며 어떻게 유저들의 피드백을 구분하고 받아들였는지, 피드백을 반영할 때 주요한 사항들은 무엇이 있는지에 대해 정리해보았습니다. 사실 설명없이 문서만으로는 부족함이 있을수도 있겠지만 많은 분들께 도움이 되길 바랍니다! :)
무...물론 카툰999도 다운받아주시면 감사...!!
객체지향에 관련해서, 가볍게 내용을 정리하였습니다.
참고서적 : 스프링 입문을 위한, 자바 객체 지향의 원리와 이해 김종민 지음
객체지향.
말은 참 어려운데. 프로그래밍 하면서 사람이 인식하는 사물 또는 실체를 하나하나 조합해서 프로그래밍 하자는 패러다임입니다.
쉽게, 객체를 가지고 놀자 이겁니다.
객체지향언어에서는
클래스(Class) 객체(Object)가 존재합니다.
클래스는 추상화 및 분류
객체는 실제를 의미합니다.
예) 사람클래스 -> 원빈 객체 / 동물 클래스 -> 고양이 객체
4대 특징
- 캡슐화
- 상속
- 추상화
- 다형성
객체지향 개념을 완벽히 이해하려면. 많이 공부해야 할거같습니다..ㅠㅠ
3. 객체지향 – 철학적인 바탕
• 이 세상이 작동하는 원리를 프로그래밍에 담자
• 이 세상이 작동하는 원리란?
1. 이 세상을 물체들로 이루어져있다
2. 물체들은 각자 고유한 특성을 가지고 있다
3. 물체와 물체들은 서로 상호작용을 하며 세상을 움직인다
• 물체의 내외는 분리되어 필요한 인터페이스를 통해 상호작용한다
4. 객체지향 – 프로그래밍에서의 장점
• 물체 내외가 분리되어있어
물체의 외부가 물체의 내부에 함부로 영향을 주지 못 한다
• 프로그래머가 신경을 쓸 부분이
물체의 내부적인 특성과 외부와의 인터페이스
두 가지로 압축된다
• 유지 및 보수가 쉬워진다
• 필요한 부분을 다른 프로젝트에서 재사용할 수 있다
6. 클래스 (class: [C] 부류, 종류)
• 세상의 수많은 물체들은 공통으로 속한 분류가 있다
• 이예찬, 문상현: 인간
• 아이폰6, 갤럭시S6: 스마트폰
• 박보영, 아이유, 김태희: 여신
• 그 물체들은 보다 저차원 적인 분류를 상속받을 수 있다
• 인간: 포유류
• 스마트폰: 통신장비
• 포유류: 동물
• 통신장비: 물체
• 동물: 물체
7. 클래스 (class: [C] 부류, 종류)
• 서로 다른 물체들의 공통된 부분을 묶어 분류하여 틀로 만든 것
• 예시
• 게임 캐릭터들은 공통적으로 HP를 가진다
• 게임 캐릭터들은 상대방으로부터 데미지를 입을 수 있다
• 게임 캐릭터들은 상대방을 공격할 수 있다.
• 틀로부터 물체들을 찍어낼 수 있으며,
물체 별로 특성을 할당할 수 있다.
• 예시
• GameCharacter p1 = new GameCharacter();
• GameCharacter p2 = new GameCharacter();
• p1.Hp = 100;
• p2.Hp = 50;
9. 정보의 은닉 (캡슐화) – 현실과의 비교
• 물체 외부에서 물체 내부의 특성을 함부로 조작하면 안 된다
• 반드시 다른 물체와의 상호작용을 통해 조작되어야 한다
• 예시
• ‘사람의 시력’이라는 값을 함부로 조작할 수는 없다
• ‘가까운 거리를 계속 보고 있기’등 상호작용을 통해 시력이 변할 수는 있다
• 참고: http://blog.variel.kr/220073616076
10. 정보의 은닉 (캡슐화) – 접근 제한자
• public vs private
• 내부의 특성은 private, 외부로 공개되는 상호작용은 public을 쓴다
• 같은 클래스 내부에서는 private 특성들에 모두 접근이 가능하다
• 다른 클래스 간에는 public 상호작용들을 통해서만 접근이 가능하다
11. 정보의 은닉 (캡슐화) - 예시
public class GameObject
{
private double hitPoint;
private double physicalDefencePoint;
private double magicalDefencePoint;
private double defencePointMultiplier;
public double GetTotalDefencePoint()
{
return (this.physicalDefencePoint + this.magicalDefencePoint)
*this.defencePointMultiplier;
}
public double Damage(double physicalAttckPoint,
double magicalAttackPoint)
{
this.hitPoint -= (physicalAttckPoint - this.physicalDefencePoint*this.defencePointMultiplier)
+ (magicalAttackPoint - this.physicalDefencePoint*this.defencePointMultiplier);
}
}
설명: 게임 오브젝트의 방어력도 다 같은 게 아니라 물리방어력, 마법방어력 등 다양한 방어력이 있다. 해당
게임 오브젝트의 총 방어력을 가져오는 상호작용이 정의가 되어 있고, 물리공격력과 마법공격력을 각각 입력
받아 데미지를 입게 만드는 상호작용이 정의가 되어 있다. 물리방어력과 마법 방어력, 체력 등의 특성들은 외
부에서 함부로 변경이 되면 안 된다.
13. 추상화 – 현실과의 비교
• 어떤 행위들을 단순화 시킨 것
• 예시
1. 다리의 대퇴사두근을 수축시켜 다리를 들어올리고
2. 반대쪽 다리의 종아리를 이완시켜 앞으로 기울인 다음
3. 다시 대퇴사두근을 이완시켜 다리를 내려놓는다
4. 이 과정을 반복한다
• 이 과정들을 추상화 하여 ‘걷기’라고 부른다
14. 추상화
• 함수를 만들어서 사용하는 것 부터가 일종의 추상화
• 복잡한 것을 더 단순하게 소스코드상에 표현할 수 있다
• 세부적인 것을 알 필요가 없으므로
소스코드를 훑었을 때 눈에 빨리 들어온다
16. 상속 – 현실과의 비교
• 인간(호모 사피엔스 사피엔스)는 생물 분류 체계에서
아래와 같은 위치에 속해있다
• 동물계
• 척추동물아문
• 포유류
• 영장목
• 유인원과
• 유인원과 동물들은 영장목의 공통된 특징들을 모두 가지고 있다
• 영장목의 동물들은 포유류의 공통된 특징들을 모두 가지고 있다
• 포유류의 동물들은 척추동물아문의 공통된 특징들을 모두 가지고 있다
• 척추동물아문의 동물들 동물계 전체의 공통된 특징을 모두 가지고 있다
17. 상속
• 부모 클래스의 특성 및 상호작용을
자식 클래스가 그대로 가지고 있는 것
public class Parent
{
private int hp;
public int GetHp() { return hp; }
public void SetHp(int value) { hp = value; }
}
public class Child : Parent
{
private int mp;
public int GetMp() { return mp; }
public void SetMp(int value) { mp = value; }
}
선언 사용
상속 받은
상호작용
18. 상속
• 자식 클래스는 부모 클래스의 모
든 것을 가지고 있기에
아래와 같은 표현도 유효 하다
• 대신 부모 클래스의 것들만 쓸
수 있다
• 부모 클래스는 자식 클래스의 모
든 것을 가지고 있지는 않으므로
아래와 같은 표현은 불가하다
Child child = new Parent();
child.SetHp(100);
child.SetMp(100);
Parent child = new Child();
child.SetHp(100);
child.SetMp(100); 불가능
불가능
19. 상속 – public vs private vs protected
• public
• 어느 곳에서든 접근 할 수 있다
• private
• 선언 한 클래스 내부에서만 접근 할 수 있다
• 자식 클래스도 접근을 못 한다
• protected
• 자식 클래스들이 접근할 수 있다
• 선언 한 클래스 내부에서도 당연히 접근할 수 있다
• 자식이 아닌 클래스에서는 접근 할 수 없다
21. 다형성 – 현실과의 비교
• 인간이 두 다리를 써서 움직이는 행위
• 개가 네 다리를 써서 움직이는 행위
• 비둘기가 두 다리를 써서 움직이는 행위
• 모두 ‘걷기’라고 할 수 있다.
• 비둘기가 두 날개를 써서 움직이는 행위
• 독수리가 두 날개를 써서 움직이는 행위
• 모두 ‘날기’라고 할 수 있다
22. 다형성
• ‘다리 달린 것(HasLeg)’이라는 부모 클래스가 있다
• 이 클래스를 상속 받은 사람, 개, 비둘기라는 클래스가 있다
• 모두 걸을 수 있다(Walk)
• 그렇다면 아래의 코드가 가능하다
HasLeg animal;
animal = new Human();
animal.Walk();
animal = new Dog();
animal.Walk();
animal = new Dove();
animal.Walk();
23. 다형성
• 같은 의미의 동작이지만 실행 주체에 따라서 내부의 동작이 다르다
• 인간의 ‘걷기’는 두 다리를 써서 걷는다
• 개의 ‘걷기’는 네 다리를 써서 걷는다
• 비둘기의 ‘걷기’는 두 다리를 써서 걷는다
• 어쨌든 ‘다리 달린 것’은 ‘걷기’를 할 수 있다
• ‘다리 달린 것’ 형태의 변수를 선언하면
실제 그것이 인간이든 개이든 비둘기이든 간에 ‘걷기’를 할 수 있다.
• 다만 그 내부의 동작은 다를 수 있다.
24. 다형성 – 소스코드
• 일반적으로 부모가 가진 메소드를 자식은 그대로 쓴다
• 하지만 자식은 그 메소드를 다시 정의할 수 있다
• 부모 입장에서는 자식이 재정의 해도 된다는 의미로
virtual이라는 키워드를 사용한다
• 자식 입장에서는 부모의 메소드를 재정의 한다는 의미로
override라는 키워드를 사용한다
public class Animal
{
public virtual void Move(int distance)
{
Console.WriteLine("I'm doing animal walking");
}
}
public class Human : Animal
{
public override void Move(int distance)
{
Console.WriteLine("I'm doing human walking");
}
}
26. 인터페이스 – 현실과의 비교
• 한 사람은 둘 이상의 부모(어머니 + 아버지)를 가질 수 없다
• 동물은 움직인다. 식물은 거의 못 움직인다. 근데 예외는 있다
• 파리지옥도 무언가를 쥘 수 있고 사람도 무언가를 쥘 수 있다
• 근데 그 둘은 완전히 다른 계에 있다(식물계 – 동물계)
• 즉, 상속 관계가 전혀 없다
• 그렇지만 쥘 수 있다는 것은 같다
• 그냥 ‘쥘 수 있는 능력이 있다’는 것을 나타낼 수는 없을까?
27. 인터페이스
• 내부에서 어떻게 동작하는지는 관심 없다
• 어차피 외부에 노출이 돼서 사용 되는 것은 상호작용, 즉 인터페이스
• 인터페이스는 다중 상속구현이 가능하다!
• 예: 사람은 ‘쥘 수 있음’, ‘걸을 수 있음’, ‘볼 수 있음’ 등의
인터페이스를 구현할 수 있다.
28. 인터페이스 – 소스코드
• 인터페이스는 public 상호작용만 가질 수 있다
• ‘~할 수 있다’고 했는데 내부에서만 할 수 있는 건 말이 안 되기 때문
• 따라서 접근 제한자를 쓸 필요가 없다 (무조건 public)
• 인터페이스를 상속 받는 클래스는 반드시 public으로
상호작용을 구현해야 한다
public interface IGrabbable
{
void Grab(Object something);
}
public interface IWalkable
{
void Walk(int distance);
}
인터페이스 선언 public class Human : IGrabbable, IWalkable
{
public void Grab(Object something)
{
// Do Something
}
public void Walk(int distance)
{
// Do Something
}
}
인터페이스 사용 (상속 및 구현)
public class Program
{
public static void Main(string[] args)
{
Human yeChan = new Human();
yeChan.Grab(yeChan);
yeChan.Walk(100);
IGrabbable grabbable = yeChan;
grabbable.Grab(yeChan);
grabbable.Walk(); // ERROR
IWalkable walkable = yeChan;
walkable.Walk(100);
walkable.Grab(yeChan); //ERROR
}
}
구현된 오브젝트 사용